using System;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using AjaxControlToolkit;
using RO.Facade3;
using RO.Common3;
using RO.Common3.Data;
using RO.WebRules;

namespace RO.Common3.Data
{
	public class AdmDbTable2 : DataSet
	{
		public AdmDbTable2()
		{
			this.Tables.Add(MakeColumns(new DataTable("AdmDbTable")));
			this.Tables.Add(MakeDtlColumns(new DataTable("AdmDbTableDef")));
			this.Tables.Add(MakeDtlColumns(new DataTable("AdmDbTableAdd")));
			this.Tables.Add(MakeDtlColumns(new DataTable("AdmDbTableUpd")));
			this.Tables.Add(MakeDtlColumns(new DataTable("AdmDbTableDel")));
			this.DataSetName = "AdmDbTable2";
			this.Namespace = "http://Rintagi.com/DataSet/AdmDbTable2";
		}

		private DataTable MakeColumns(DataTable dt)
		{
			DataColumnCollection columns = dt.Columns;
			columns.Add("TableId3", typeof(string));
			columns.Add("SystemId3", typeof(string));
			columns.Add("TableName3", typeof(string));
			columns.Add("TableDesc3", typeof(string));
			columns.Add("TblObjective3", typeof(string));
			columns.Add("VirtualTbl3", typeof(string));
			columns.Add("MultiDesignDb3", typeof(string));
			columns.Add("ModelSample", typeof(string));
			columns.Add("SyncByDb", typeof(string));
			columns.Add("AnalToDb", typeof(string));
			columns.Add("SyncToDb", typeof(string));
			columns.Add("UploadSheet", typeof(string));
			columns.Add("SheetNameList", typeof(string));
			columns.Add("RowsToExamine", typeof(string));
			columns.Add("BtnScan", typeof(string));
			columns.Add("ModifiedBy3", typeof(string));
			columns.Add("ModifiedOn3", typeof(string));
			columns.Add("LastSyncDt3", typeof(string));
			columns.Add("VirtualSql3", typeof(string));
			return dt;
		}

		private DataTable MakeDtlColumns(DataTable dt)
		{
			DataColumnCollection columns = dt.Columns;
			columns.Add("TableId3", typeof(string));
			columns.Add("ColumnId5", typeof(string));
			columns.Add("ColumnIndex5", typeof(string));
			columns.Add("ExternalTable5", typeof(string));
			columns.Add("ColumnName5", typeof(string));
			columns.Add("DataType5", typeof(string));
			columns.Add("ColumnLength5", typeof(string));
			columns.Add("ColumnScale5", typeof(string));
			columns.Add("DefaultValue5", typeof(string));
			columns.Add("AllowNulls5", typeof(string));
			columns.Add("ColumnIdentity5", typeof(string));
			columns.Add("PrimaryKey5", typeof(string));
			columns.Add("IsIndexU5", typeof(string));
			columns.Add("IsIndex5", typeof(string));
			columns.Add("ColObjective5", typeof(string));
			return dt;
		}
	}
}

namespace RO.Web
{
	public partial class AdmDbTableModule : RO.Web.ModuleBase
	{
		private bool bAllowNulls5 = false;

		private const string KEY_lastAddedRow = "Cache:lastAddedRow3_2";
		private const string KEY_lastSortOrd = "Cache:lastSortOrd3_2";
		private const string KEY_lastSortImg = "Cache:lastSortImg3_2";
		private const string KEY_lastSortCol = "Cache:lastSortCol3_2";
		private const string KEY_lastSortExp = "Cache:lastSortExp3_2";
		private const string KEY_lastSortUrl = "Cache:lastSortUrl3_2";
		private const string KEY_lastSortTog = "Cache:lastSortTog3_2";
		private const string KEY_lastImpPwdOvride = "Cache:lastImpPwdOvride3_2";
		private const string KEY_cntImpPwdOvride = "Cache:cntImpPwdOvride3_2";
		private const string KEY_currPageIndex = "Cache:currPageIndex3_2";
		private const string KEY_bHiImpVisible = "Cache:bHiImpVisible3_2";
		private const string KEY_bShImpVisible = "Cache:bShImpVisible3_2";
		private const string KEY_dtAdmDbTableGrid = "Cache:dtAdmDbTableGrid";
		private const string KEY_scrImport = "Cache:scrImport3_2";
		private const string KEY_dtScreenHlp = "Cache:dtScreenHlp3_2";
		private const string KEY_dtClientRule = "Cache:dtClientRule3_2";
		private const string KEY_dtAuthCol = "Cache:dtAuthCol3_2";
		private const string KEY_dtAuthRow = "Cache:dtAuthRow3_2";
		private const string KEY_dtLabel = "Cache:dtLabel3_2";
		private const string KEY_dtCriHlp = "Cache:dtCriHlp3_2";
		private const string KEY_dtScrCri = "Cache:dtScrCri3_2";
		private const string KEY_dsScrCriVal = "Cache:dsScrCriVal3_2";

		private const string KEY_dtSystemId3 = "Cache:dtSystemId3";
		private const string KEY_dtSheetNameList = "Cache:dtSheetNameList";
		private const string KEY_dtModifiedBy3 = "Cache:dtModifiedBy3";
		private const string KEY_dtDataType5 = "Cache:dtDataType5";

		private const string KEY_dtSystems = "Cache:dtSystems3_2";
		private const string KEY_sysConnectionString = "Cache:sysConnectionString3_2";
		private const string KEY_dtAdmDbTable2List = "Cache:dtAdmDbTable2List";
		private const string KEY_bNewVisible = "Cache:bNewVisible3_2";
		private const string KEY_bNewSaveVisible = "Cache:bNewSaveVisible3_2";
		private const string KEY_bCopyVisible = "Cache:bCopyVisible3_2";
		private const string KEY_bCopySaveVisible = "Cache:bCopySaveVisible3_2";
		private const string KEY_bDeleteVisible = "Cache:bDeleteVisible3_2";
		private const string KEY_bUndoAllVisible = "Cache:bUndoAllVisible3_2";
		private const string KEY_bUpdateVisible = "Cache:bUpdateVisible3_2";

		private const string KEY_bClCriVisible = "Cache:bClCriVisible3_2";
		private byte LcSystemId;
		private string LcSysConnString;
		private string LcAppConnString;
		private string LcAppDb;
		private string LcDesDb;
		private string LcAppPw;
		protected System.Collections.Generic.Dictionary<string, DataRow> LcAuth;

		//WebRule: Custom function to hide or show icons/upload
        private void HideShowIcons(object sender, EventArgs e)
        {
            if (Config.DeployType == "PRD" && base.SystemsList.Rows.Find(cSystemId.SelectedValue)["dbAppDatabase"].ToString() != base.CPrj.EntityCode + "View")
            {
                cSyncByDb.Visible = false; cAnalToDb.Visible = false; cModelSample.Visible = false; cSyncToDb.Visible = false;
            }
            else
            {
                cSyncByDb.Visible = true; cAnalToDb.Visible = true; cModelSample.Visible = true; cSyncToDb.Visible = true;
            }
        }

        private void HideShowUpload(bool bHide)
        {
            if (bHide)
            {
                cUploadSheetP1.Visible = false; cUploadSheetP2.Visible = false;
                cSheetNameListP1.Visible = false; cSheetNameListP2.Visible = false;
                cRowsToExamineP1.Visible = false; cRowsToExamineP2.Visible = false;
                cBtnScanP1.Visible = false; cBtnScanP2.Visible = false;
            }
            else
            {
                cUploadSheetP1.Visible = true; cUploadSheetP2.Visible = true;
                cSheetNameListP1.Visible = true; cSheetNameListP2.Visible = true;
                cRowsToExamineP1.Visible = true; cRowsToExamineP2.Visible = true;
                cBtnScanP1.Visible = true; cBtnScanP2.Visible = true;
            }
        }

		//WebRule: Function to upload Excel / scan uploaded sample
        private void ScanExcelSample(object sender, EventArgs e, bool populateSheetNameOnly)
        {
            DataTable dtAdmDbTableGrid = (DataTable)Session[KEY_dtAdmDbTableGrid];
            if (cUploadSheet.Text != string.Empty && (string.IsNullOrEmpty(cTableId3.Text) || dtAdmDbTableGrid.Rows.Count == 0))
            {
                string fileName = new FileInfo(Server.MapPath(cUploadSheet.Text)).Name;
                string path = new FileInfo(Server.MapPath(cUploadSheet.Text)).FullName;
                string rowsToExamine = cRowsToExamine.Text;
                string[] sheets = null;
                System.Collections.Generic.List<string> messages = new System.Collections.Generic.List<string>();
                try
                {
                    sheets = (new XLSImport(Config.WsXlsUrl)).GetSheetNames(path);
                }
                catch (Exception er)
                {
                    PreMsgPopup(er.Message);
                    return;
                }

                if (populateSheetNameOnly)
                {
                    cSheetNameList.DataSource = sheets.Select(x => new {SheetNameList=x,SheetNameListText=x});
                    cSheetNameList.DataBind();
                    return;
                }

                string sheetName = cSheetNameList.SelectedValue;
                DataTable dtImp = null;

                try
                {
                    dtImp = RO.Common3.XmlUtils.XmlToDataSet((new XLSImport(Config.WsXlsUrl)).ImportFile(fileName, sheetName, "1", path)).Tables[0];
                }
                catch (Exception er)
                {
                    PreMsgPopup(er.Message);
                    return;
                }
                System.Collections.Generic.List<DataStructure> columns = RO.Common3.Utils.AnalyseExcelData(dtImp, string.IsNullOrEmpty(rowsToExamine) ? 100 : int.Parse(rowsToExamine));
                if (columns.Count == 0 || dtImp.Rows.Count == 0)
                {
                    PreMsgPopup("No information found in the spreadsheet");
                    return;
                }
                else if (dtImp.Rows.Count < 2)
                {
                    messages.Add("No data sample to analyse, all columns are treated as string, i.e. NVarchar(max)");
                }

                DataTable dtd = (DataTable)Session[KEY_dtDataType5];
                if (dtd == null)
                {
                    try
                    {
                        dtd = (new AdminSystem()).GetDdl(2, "GetDdlDataType3S17", true, true, 0, string.Empty, (string)Session[KEY_sysConnectionString], LcAppPw, string.Empty, base.LImpr, base.LCurr);
                    }
                    catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
                    Session[KEY_dtDataType5] = dtd;
                }
                System.Collections.Generic.Dictionary<string, int> dataType = new System.Collections.Generic.Dictionary<string, int>();
                foreach (DataRow dr in dtd.Rows)
                {
                    if (!string.IsNullOrEmpty(dr[0].ToString())) dataType.Add(dr[1].ToString(), int.Parse(dr[0].ToString()));
                }
                dtAdmDbTableGrid.Clear();
                DataRow drKey = dtAdmDbTableGrid.NewRow();
                string TableName = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(Regex.Replace(sheetName, @"\s+", "").ToLower());
                drKey[1] = 10;
                drKey[3] = TableName.Left(13) + "Id";
                drKey[4] = dataType["Int"];
                drKey[5] = "Int";
                drKey[6] = 4;
                drKey[10] = "Y";
                drKey[11] = "Y";
                drKey[14] = "Unique Internal key, must present";
                cTableName3.Text = TableName.Left(13);
                dtAdmDbTableGrid.Rows.Add(drKey);
                cTableDesc3.Text = sheetName;
                int ii = 2; int columnNameFix = 0;
                foreach (DataStructure x in columns)
                {
                    if (!string.IsNullOrEmpty(x.ColumnName))
                    {
                        if (x.ColumnType == "Float")
                        {
                            if (x.maxDecimal <= 2) x.ColumnType = "Money";
                        }
                        DataRow dr = dtAdmDbTableGrid.NewRow();
                        string trimmedColumnName = Regex.Replace(x.ColumnName, @"(\s|[*#.])+", "");
                        dr[1] = ii * 10;
                        dr[3] = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(trimmedColumnName.Left(15).ToLower());
                        dr[4] = dataType[x.ColumnType];
                        dr[5] = x.ColumnType;
                        dr[6] = x.ColumnType == "Int" ? 4
                                : x.ColumnType == "Date" || x.ColumnType == "DateTime" ? 8
                                : x.ColumnType == "Float" ? 8
                                : x.ColumnType == "Money" ? 8
                                : x.ColumnWidth;
                        dr[7] = x.ColumnType == "Float" ? x.maxDecimal : dr[7];
                        dr[9] = x.hasEmpty ? "Y" : "N";
                        dr[14] = (trimmedColumnName.Length > 15 ? ">>Column Name truncated to 15 character - " : "") + x.ColumnName;
                        dtAdmDbTableGrid.Rows.Add(dr);
                        columnNameFix = columnNameFix + (trimmedColumnName.Length > 15 ? 1 : 0);
                        ii = ii + 1;
                    };
                }
                messages.Add(columns.Count.ToString() + " analysed" + (columnNameFix > 0 ? ", " + columnNameFix.ToString() + " with column name being truncated to 15 characters" : ""));
                bInfoNow.Value = "Y"; PreMsgPopup(string.Join("\n", messages.ToArray()));
                cAdmDbTableGrid_DataBind(dtAdmDbTableGrid.DefaultView);
            }
            else
            {
                PreMsgPopup("We can only analyse/popular new table or table without column already defined");
            }

        }

		// *** WebRule End *** //

		public AdmDbTableModule()
		{
			this.Init += new System.EventHandler(Page_Init);
		}

		protected void Page_Load(object sender, System.EventArgs e)
		{
			Thread.CurrentThread.CurrentCulture = new CultureInfo(base.LUser.Culture);
			string lang2 = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
			string lang = "en,zh".IndexOf(lang2) < 0 ? lang2 : Thread.CurrentThread.CurrentCulture.Name;
			try { ScriptManager.RegisterStartupScript(this, this.GetType(), "datepicker_i18n", File.ReadAllText(Request.MapPath("~/scripts/i18n/jquery.ui.datepicker-" + lang + ".js")), true); } catch { };
			if (!IsPostBack) { Session.Remove(KEY_dtScrCri); }
			int ii = 0; DataView dvCri = GetScrCriteria(); SetCriHolder(ii, dvCri);
			bConfirm.Value = "Y";
			// To get around ajax not displaying ErrMsg and InfoMsg; Set them to Y to show immediately:
			bErrNow.Value = "N"; bInfoNow.Value = "N"; bExpNow.Value = "N";
			CtrlToFocus.Value = string.Empty;
			EnableValidators(false);
			if (!IsPostBack)
			{
				DataTable dtMenuAccess = (new MenuSystem()).GetMenu(base.LUser.CultureId, 3, base.LImpr, LcSysConnString, LcAppPw,2, null, null);
				if (dtMenuAccess.Rows.Count == 0 && !IsCronInvoked())
				{
				    string message = (new AdminSystem()).GetLabel(base.LUser.CultureId, "cSystem", "AccessDeny", null, null, null);
				    throw new Exception(message);
				}
				cFind.Attributes.Add("OnKeyDown", "return EnterKeyCtrl(event,'" + cFindButton.ClientID + "')");
				cPgSize.Attributes.Add("OnKeyDown", "return EnterKeyCtrl(event,'" + cPgSizeButton.ClientID + "')");
				Session[KEY_lastImpPwdOvride] = 0; Session[KEY_cntImpPwdOvride] = 0; Session[KEY_currPageIndex] = 0;
				Session.Remove(KEY_dtAdmDbTableGrid);
				Session.Remove(KEY_lastSortCol);
				Session.Remove(KEY_lastSortExp);
				Session.Remove(KEY_lastSortImg);
				Session.Remove(KEY_lastSortUrl);
				Session.Remove(KEY_dtAdmDbTable2List);
				Session.Remove(KEY_dtSystems);
				Session.Remove(KEY_sysConnectionString);
				Session.Remove(KEY_sysConnectionString + "Pwd");
				Session.Remove(KEY_dtScreenHlp);
				Session.Remove(KEY_dtClientRule);
				Session.Remove(KEY_dtAuthCol);
				Session.Remove(KEY_dtAuthRow);
				Session.Remove(KEY_dtLabel);
				Session.Remove(KEY_dtCriHlp);
				Session.Remove(KEY_dtSystemId3);
				Session.Remove(KEY_dtSheetNameList);
				Session.Remove(KEY_dtModifiedBy3);
				Session.Remove(KEY_dtDataType5);
				SetButtonHlp();
				GetSystems();
				SetColumnAuthority();
				GetGlobalFilter();
				GetScreenFilter();
				GetPageInfo();
				GetCriteria(dvCri);
				DataTable dtHlp = GetScreenHlp();
				cHelpMsg.HelpTitle = dtHlp.Rows[0]["ScreenTitle"].ToString(); cHelpMsg.HelpMsg = dtHlp.Rows[0]["DefaultHlpMsg"].ToString();
				cFootLabel.Text = dtHlp.Rows[0]["FootNote"].ToString();
				if (cFootLabel.Text == string.Empty) { cFootLabel.Visible = false; }
				cTitleLabel.Text = dtHlp.Rows[0]["ScreenTitle"].ToString();
				DataTable dt = GetScreenTab();
				cTab3.InnerText = dt.Rows[0]["TabFolderName"].ToString();
				cTab4.InnerText = dt.Rows[1]["TabFolderName"].ToString();
				SetClientRule(null,false);
				IgnoreConfirm(); InitPreserve();
				cSystemId_SelectedIndexChanged(null, null);
				try
				{
					(new AdminSystem()).LogUsage(base.LUser.UsrId, string.Empty, dtHlp.Rows[0]["ScreenTitle"].ToString(), 2, 0, 0, string.Empty, LcSysConnString, LcAppPw);
				}
				catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
				// *** Criteria Trigger (before) Web Rule starts here *** //
				PopAdmDbTable2List(sender, e, true, null);
				if (cAuditButton.Attributes["OnClick"] == null || cAuditButton.Attributes["OnClick"].IndexOf("AdmScrAudit.aspx") < 0) { cAuditButton.Attributes["OnClick"] += "SearchLink('AdmScrAudit.aspx?cri0=2&typ=N&sys=3','','',''); return false;"; }
				cDataType5Search_Script();
				//WebRule: Confirm message for Synchronization icons
                if (cBtnScan.Attributes["OnClick"] == null || cBtnScan.Attributes["OnClick"].IndexOf("_bConfirm") < 0) { cBtnScan.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';"; }
                if (cSyncByDb.Attributes["OnClick"] == null || cSyncByDb.Attributes["OnClick"].IndexOf("_bConfirm") < 0) { cSyncByDb.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';"; }
                if (cSyncByDb.Attributes["OnClick"] == null || cSyncByDb.Attributes["OnClick"].IndexOf("return confirm") < 0) {cSyncByDb.Attributes["OnClick"] += "return confirm('Proceed to synchronize by physical database for sure?');";}
                if (cSyncToDb.Attributes["OnClick"] == null || cSyncToDb.Attributes["OnClick"].IndexOf("return confirm") < 0) {cSyncToDb.Attributes["OnClick"] += "return confirm('Proceed to synchronize to physical database for sure?');";}
                HideShowIcons(sender, e); HideShowUpload(true);
				// *** WebRule End *** //
				cBrowse.Attributes.Add("OnChange", "__doPostBack('" + cBrowseButton.ClientID.Replace("_", "$") + "','')");
				DataTable dtLabel = (new AdminSystem()).GetLabels(base.LUser.CultureId, "cGrid", null, null, null);
				if (dtLabel != null)
				{
				    cGridFtrLabel.Text = dtLabel.Rows[0][1].ToString();
				    cGridFndLabel.Text = dtLabel.Rows[1][1].ToString();
				    cImpPwdLabel.Text = dtLabel.Rows[2][1].ToString();
				    cImportPwd.ToolTip = dtLabel.Rows[3][1].ToString();
				    cGridWksLabel.Text = dtLabel.Rows[4][1].ToString();
				    cGridStrLabel.Text = dtLabel.Rows[5][1].ToString();
				    cStartRow.ToolTip = dtLabel.Rows[6][1].ToString();
				}
			}
			else
			{
				DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
				if (dt != null)
				{
					string sr = ViewState["_SortColumn"] as string;
					if (sr != null) { dt.DefaultView.Sort = sr.ToString(); }
					string rf = ViewState["_RowFilter"] as string;
					if (rf != null) { dt.DefaultView.RowFilter = rf.ToString(); }
				}
			}
			if (IsPostBack && !ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack) {SetClientRule(null,false);};
			if (!IsPostBack)	// Test for Viewstate being lost.
			{
				bViewState.Text = "Y";
				string xx = Session["Idle:" + Request.Url.PathAndQuery] as string;
				if (xx == "Y")
				{
					Session.Remove("Idle:" + Request.Url.PathAndQuery);
					bInfoNow.Value = "Y"; PreMsgPopup("Page has been idled past preset limit and no longer valid, please be notified that it has been reloaded.");
				}
			}
			else if (string.IsNullOrEmpty(bViewState.Text))		// Viewstate is lost.
			{
				Session["Idle:" + Request.Url.PathAndQuery] = "Y"; this.Redirect(Request.Url.PathAndQuery);
			}
			if (!string.IsNullOrEmpty(cCurrentTab.Value))
			{
				HtmlControl wcTab = this.FindControl(cCurrentTab.Value.Substring(1)) as HtmlControl;
				wcTab.Style["display"] = "block";
			}
			ScriptManager.RegisterStartupScript(this, this.GetType(), "ScreenLabel", this.ClientID + "={" + string.Join(",", (from dr in GetLabel().AsEnumerable() select string.Format("{0}: {{msg:'{1}',hint:'{2}'}}", "c" + dr.Field<string>("ColumnName") + (dr.Field<int?>("TableId").ToString()), (dr.Field<string>("ErrMessage") ?? string.Empty).Replace("'", "\\'").Replace("\r", "\\r").Replace("\n", "\\n"), (dr.Field<string>("TbHint") ?? string.Empty).Replace("'", "\\'").Replace("\r", "\\r").Replace("\n", "\\n"))).ToArray()) + "};", true);
		}

		protected void Page_Init(object sender, EventArgs e)
		{
			// *** Page Init (Front of) Web Rule starts here *** //
			InitializeComponent();
			//WebRule: Tie hide / show icons to cSystemId event
            cSystemId.SelectedIndexChanged += HideShowIcons;

			// *** WebRule End *** //
		}

		#region Web Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			CheckAuthentication(true);
			if (LcSysConnString == null)
			{
				SetSystem(3);
				try
				{
					DataTable dt;
					dt = (new AdminSystem()).GetAuthRow(2,base.LImpr.RowAuthoritys,LcSysConnString,LcAppPw);
					Session[KEY_dtAuthRow] = dt;
					DataRow dr = dt.Rows[0];
					if (!((dr["AllowUpd"].ToString() == "N" || dr["ViewOnly"].ToString() == "G") && dr["AllowAdd"].ToString() == "N") && (Request.QueryString["enb"] == null || Request.QueryString["enb"] != "N"))
					{
						cAdmDbTableGrid.PreRender += new EventHandler(cAdmDbTableGrid_OnPreRender);
					}
				}
				catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
			}

		}
		#endregion

		private void SetSystem(byte SystemId)
		{
			LcSystemId = SystemId;
			LcSysConnString = base.SysConnectStr(SystemId);
			LcAppConnString = base.AppConnectStr(SystemId);
			LcDesDb = base.DesDb(SystemId);
			LcAppDb = base.AppDb(SystemId);
			LcAppPw = base.AppPwd(SystemId);
			try
			{
				base.CPrj = new CurrPrj(((new RobotSystem()).GetEntityList()).Rows[0]);
				DataRow row = base.SystemsList.Rows.Find(SystemId);
				base.CSrc = new CurrSrc(true, row);
				base.CTar = new CurrTar(true, row);
				if ((Config.DeployType == "DEV" || row["dbAppDatabase"].ToString() == base.CPrj.EntityCode + "View") && !(base.CPrj.EntityCode != "RO" && row["SysProgram"].ToString() == "Y") && (new AdminSystem()).IsRegenNeeded(string.Empty,2,0,0,LcSysConnString,LcAppPw))
				{
					(new GenScreensSystem()).CreateProgram(2, "Data Table and Columns", row["dbAppDatabase"].ToString(), base.CPrj, base.CSrc, base.CTar, LcAppConnString, LcAppPw);
					this.Redirect(Request.RawUrl);
				}
			}
			catch (Exception e) { bErrNow.Value = "Y"; PreMsgPopup(e.Message); }
		}

		private void EnableValidators(bool bEnable)
		{
			foreach (System.Web.UI.WebControls.WebControl va in Page.Validators)
			{
				if (bEnable) {va.Enabled = true;} else {va.Enabled = false;}
			}
		}

		private void CheckAuthentication(bool pageLoad)
		{
			if (IsCronInvoked())
			{
				AnonymousLogin();
				LCurr.SystemId = 3;
				LCurr.DbId = 3;
			}
			else CheckAuthentication(pageLoad, true);
		}

		private void SetButtonHlp()
		{
			try
			{
				DataTable dt;
				dt = (new AdminSystem()).GetButtonHlp(2,0,0,base.LUser.CultureId,LcSysConnString,LcAppPw);
				if (dt != null && dt.Rows.Count > 0)
				{
					foreach (DataRow dr in dt.Rows)
					{
						if (dr["ButtonTypeName"].ToString() == "ClearCri") { cClearCriButton.CssClass = "ButtonImg ClearCriButtonImg"; Session[KEY_bClCriVisible] = base.GetBool(dr["ButtonVisible"].ToString()); cClearCriButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						else if (dr["ButtonTypeName"].ToString() == "Save") { cSaveButton.CssClass = "ButtonImg SaveButtonImg"; cSaveButton.Text = dr["ButtonName"].ToString(); cSaveButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cSaveButton.ToolTip = dr["ButtonToolTip"].ToString(); Session[KEY_bUpdateVisible] = cSaveButton.Visible; }
						else if (dr["ButtonTypeName"].ToString() == "ExpTxt") { cExpTxtButton.CssClass = "ButtonImg ExpTxtButtonImg"; cExpTxtButton.Text = dr["ButtonName"].ToString(); cExpTxtButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cExpTxtButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						else if (dr["ButtonTypeName"].ToString() == "ExpRtf") { cExpRtfButton.CssClass = "ButtonImg ExpRtfButtonImg"; cExpRtfButton.Text = dr["ButtonName"].ToString(); cExpRtfButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cExpRtfButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						else if (dr["ButtonTypeName"].ToString() == "UndoAll") { cUndoAllButton.CssClass = "ButtonImg UndoAllButtonImg"; cUndoAllButton.Text = dr["ButtonName"].ToString(); cUndoAllButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cUndoAllButton.ToolTip = dr["ButtonToolTip"].ToString(); Session[KEY_bUndoAllVisible] = cUndoAllButton.Visible; }
						else if (dr["ButtonTypeName"].ToString() == "More") { cMoreButton.CssClass = "ButtonImg MoreButtonImg"; cMoreButton.Text = dr["ButtonName"].ToString(); cMoreButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cMoreButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						else if (dr["ButtonTypeName"].ToString() == "SaveClose") { cSaveCloseButton.CssClass = "ButtonImg SaveCloseButtonImg"; cSaveCloseButton.Text = dr["ButtonName"].ToString(); cSaveCloseButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cSaveCloseButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						else if (dr["ButtonTypeName"].ToString() == "Edit") { cEditButton.CssClass = "ButtonImg EditButtonImg"; cEditButton.Text = dr["ButtonName"].ToString(); cEditButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cEditButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						else if (dr["ButtonTypeName"].ToString() == "Preview") { cPreviewButton.CssClass = "ButtonImg PreviewButtonImg"; cPreviewButton.Text = dr["ButtonName"].ToString(); cPreviewButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cPreviewButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						if (dr["ButtonTypeName"].ToString() == "Audit") { cAuditButton.CssClass = "ButtonImg AuditButtonImg"; cAuditButton.Text = dr["ButtonName"].ToString(); cAuditButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cAuditButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						if (dr["ButtonTypeName"].ToString() == "Clear") { cClearButton.CssClass = "ButtonImg ClearButtonImg"; cClearButton.Text = dr["ButtonName"].ToString(); cClearButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cClearButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						else if (dr["ButtonTypeName"].ToString() == "New") { cNewButton.CssClass = "ButtonImg NewButtonImg"; cNewButton.Text = dr["ButtonName"].ToString(); cNewButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cNewButton.ToolTip = dr["ButtonToolTip"].ToString(); Session[KEY_bNewVisible] = cNewButton.Visible; }
						else if (dr["ButtonTypeName"].ToString() == "NewSave") { cNewSaveButton.CssClass = "ButtonImg NewSaveButtonImg"; cNewSaveButton.Text = dr["ButtonName"].ToString(); cNewSaveButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cNewSaveButton.ToolTip = dr["ButtonToolTip"].ToString(); Session[KEY_bNewSaveVisible] = cNewSaveButton.Visible; }
						else if (dr["ButtonTypeName"].ToString() == "Copy") { cCopyButton.CssClass = "ButtonImg CopyButtonImg"; cCopyButton.Text = dr["ButtonName"].ToString(); cCopyButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cCopyButton.ToolTip = dr["ButtonToolTip"].ToString(); Session[KEY_bCopyVisible] = cCopyButton.Visible;}
						else if (dr["ButtonTypeName"].ToString() == "CopySave") { cCopySaveButton.CssClass = "ButtonImg CopySaveButtonImg"; cCopySaveButton.Text = dr["ButtonName"].ToString(); cCopySaveButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cCopySaveButton.ToolTip = dr["ButtonToolTip"].ToString(); Session[KEY_bCopySaveVisible] = cCopySaveButton.Visible;}
						else if (dr["ButtonTypeName"].ToString() == "Delete") { cDeleteButton.CssClass = "ButtonImg DeleteButtonImg"; cDeleteButton.Text = dr["ButtonName"].ToString(); cDeleteButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cDeleteButton.ToolTip = dr["ButtonToolTip"].ToString(); Session[KEY_bDeleteVisible] = cDeleteButton.Visible;}
						if (dr["ButtonTypeName"].ToString() == "InsRow") { cInsRowButton.CssClass = "ButtonImg InsRowButtonImg"; cInsRowButton.Text = "ADD"; cInsRowButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cInsRowButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						else if (dr["ButtonTypeName"].ToString() == "PgSize") { cPgSizeButton.CssClass = "ButtonImg PgSizeButtonImg"; cPgSizeButton.Text = string.Empty; cPgSizeButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cPgSizeButton.ToolTip = dr["ButtonToolTip"].ToString(); cPgSize.Visible = base.GetBool(dr["ButtonVisible"].ToString()); }
						else if (dr["ButtonTypeName"].ToString() == "First") { cFirstButton.CssClass = "ButtonImg FirstButtonImg"; cFirstButton.Text = string.Empty; cFirstButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cFirstButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						else if (dr["ButtonTypeName"].ToString() == "Prev") { cPrevButton.CssClass = "ButtonImg PrevButtonImg"; cPrevButton.Text = string.Empty; cPrevButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cPrevButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						else if (dr["ButtonTypeName"].ToString() == "Next") { cNextButton.CssClass = "ButtonImg NextButtonImg"; cNextButton.Text = string.Empty; cNextButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cNextButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						else if (dr["ButtonTypeName"].ToString() == "Last") { cLastButton.CssClass = "ButtonImg LastButtonImg"; cLastButton.Text = string.Empty; cLastButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cLastButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						else if (dr["ButtonTypeName"].ToString() == "Find") { cFindButton.CssClass = "ButtonImg FindButtonImg"; cFindButton.Text = string.Empty; cFindButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cFindButton.ToolTip = dr["ButtonToolTip"].ToString(); cFind.Visible = base.GetBool(dr["ButtonVisible"].ToString()); }
						else if (dr["ButtonTypeName"].ToString() == "Import") { cImportButton.CssClass = "ButtonImg ImportButtonImg"; cImportButton.Text = string.Empty; cImportButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cImportButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						else if (dr["ButtonTypeName"].ToString() == "Continue") { cContinueButton.CssClass = "ButtonImg ContinueButtonImg"; cContinueButton.Text = string.Empty; cContinueButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cContinueButton.ToolTip = dr["ButtonToolTip"].ToString(); }
						else if (dr["ButtonTypeName"].ToString() == "HideImp") { cHideImpButton.CssClass = "ButtonImg HideImpButtonImg"; cHideImpButton.Text = string.Empty; cHideImpButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cHideImpButton.ToolTip = dr["ButtonToolTip"].ToString(); Session[KEY_bHiImpVisible] = base.GetBool(dr["ButtonVisible"].ToString()); cHideImpButton.Visible = false; }
						else if (dr["ButtonTypeName"].ToString() == "ShowImp") { cShowImpButton.CssClass = "ButtonImg ShowImpButtonImg"; cShowImpButton.Text = string.Empty; cShowImpButton.Visible = base.GetBool(dr["ButtonVisible"].ToString()); cShowImpButton.ToolTip = dr["ButtonToolTip"].ToString(); Session[KEY_bShImpVisible] = cShowImpButton.Visible; }
					}
				}
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
		}

		private DataTable GetClientRule()
		{
			DataTable dtRul = (DataTable)Session[KEY_dtClientRule];
			if (dtRul == null)
			{
				CheckAuthentication(false);
				try
				{
					dtRul = (new AdminSystem()).GetClientRule(2,0,base.LUser.CultureId,LcSysConnString,LcAppPw);
				}
				catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
				Session[KEY_dtClientRule] = dtRul;
			}
			return dtRul;
		}

		private void SetClientRule(ListViewDataItem ee, bool isEditItem)
		{
			DataView dvRul = new DataView(GetClientRule());
			if (ee != null) {dvRul.RowFilter = "MasterTable = 'N'";} else {dvRul.RowFilter = "MasterTable <> 'N'";}
			if (dvRul.Count > 0)
			{
				WebControl cc = null;
				string srp = string.Empty;
				string sn = string.Empty;
				string st = string.Empty;
				string sg = string.Empty;
				int ii = 0;
				int jj = 0;
				Regex missing = new Regex("@[0-9]+@");
				string lang2 = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
				string lang = "en,zh".IndexOf(lang2) < 0 ? lang2 : Thread.CurrentThread.CurrentCulture.Name;
				foreach (DataRowView drv in dvRul)
				{
					if (ee == null || drv["ScriptEvent"].ToString().Substring(0,2).ToLower() != "on" || (cAdmDbTableGrid.EditIndex > -1 && GetDataItemIndex(cAdmDbTableGrid.EditIndex) == ee.DataItemIndex))
					{
						srp = drv["ScriptName"].ToString();
						srp = srp.Replace("@cLang@", "\'" + lang + "\'");
						if (drv["ParamName"].ToString() != string.Empty)
						{
							StringBuilder sbName =  new StringBuilder();
							StringBuilder sbType =  new StringBuilder();
							StringBuilder sbInGrid =  new StringBuilder();
							sbName.Append(drv["ParamName"].ToString().Trim());
							sbType.Append(drv["ParamType"].ToString().Trim());
							sbInGrid.Append(drv["ParamInGrid"].ToString().Trim());
							ii = 0;
							while (sbName.Length > 0)
							{
								sn = Utils.PopFirstWord(sbName,(char)44); st = Utils.PopFirstWord(sbType,(char)44);sg = Utils.PopFirstWord(sbInGrid,(char)44);
								if (ee != null && sg == "Y")
								{
									if (st.ToLower() == "combobox" && isEditItem) {srp = srp.Replace("@" + ii.ToString() + "@","'"+((RoboCoder.WebControls.ComboBox)ee.FindControl(sn)).KeyID+"'");} else {srp = srp.Replace("@" + ii.ToString() + "@","'"+((WebControl)ee.FindControl(sn + (!isEditItem ? "l" : ""))).ClientID+"'");}
								}
								else
								{
									if (st.ToLower() == "combobox") {srp = srp.Replace("@" + ii.ToString() + "@","'"+((RoboCoder.WebControls.ComboBox)this.FindControl(sn)).KeyID+"'");} else {srp = srp.Replace("@" + ii.ToString() + "@","'"+((WebControl)this.FindControl(sn)).ClientID+"'");}
								}
								ii = ii + 1;
							}
						}
						if (drv["ScriptEvent"].ToString() == "js")
						{
							ScriptManager.RegisterStartupScript(this, this.GetType(), drv["ColName"].ToString() + "_" + drv["ScriptName"].ToString() + jj.ToString(),"<script>"+ drv["ClientRuleProg"].ToString() + srp + "</script>", false);
						}
						else if (drv["ScriptEvent"].ToString() == "css")
						{
							ScriptManager.RegisterClientScriptBlock(this, this.GetType(), drv["ColName"].ToString() + "_" + drv["ScriptName"].ToString() + jj.ToString(),"<style>"+ drv["ClientRuleProg"].ToString() + "</style>", false);
						}
						else if (drv["ScriptEvent"].ToString() == "css_link")
						{
							ScriptManager.RegisterClientScriptBlock(this, this.GetType(), drv["ColName"].ToString() + "_" + drv["ScriptName"].ToString() + jj.ToString(),"<link  rel='stylesheet' type='text/css' href='"+ drv["ClientRuleProg"].ToString() + "' />", false);
						}
						else if (drv["ScriptEvent"].ToString() == "js_link")
						{
							ScriptManager.RegisterClientScriptBlock(this, this.GetType(), drv["ColName"].ToString() + "_" + drv["ScriptName"].ToString() + jj.ToString(),"<script type='text/javascript' src='"+ drv["ClientRuleProg"].ToString() + "'></script>", false);
						}
						else
						{
							srp = missing.Replace(srp, "''");
							string scriptEvent = drv["ScriptEvent"].ToString().TrimStart(new char[]{'_'});
							if (ee != null) {cc = ee.FindControl(drv["ColName"].ToString()) as WebControl;} else {cc = this.FindControl(drv["ColName"].ToString()) as WebControl;}
							if (cc != null && (cc.Attributes[scriptEvent] == null || cc.Attributes[scriptEvent].IndexOf(srp) < 0)) {cc.Attributes[scriptEvent] += srp;}
							if (ee != null && drv["ScriptEvent"].ToString().Substring(0,2).ToLower() != "on")
							{
								cc = ee.FindControl(drv["ColName"].ToString() + "l") as WebControl;
								if (cc != null && (cc.Attributes[scriptEvent] == null || cc.Attributes[scriptEvent].IndexOf(srp) < 0)) {cc.Attributes[scriptEvent] += srp;}
							}
						}
					}
					jj = jj + 1;
				}
			}
		}

		private DataTable GetScreenCriHlp()
		{
			DataTable dtCriHlp = (DataTable)Session[KEY_dtCriHlp];
			if (dtCriHlp == null)
			{
				CheckAuthentication(false);
				try
				{
					dtCriHlp = (new AdminSystem()).GetScreenCriHlp(2,base.LUser.CultureId,LcSysConnString,LcAppPw);
				}
				catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
				Session[KEY_dtCriHlp] = dtCriHlp;
			}
			return dtCriHlp;
		}

		private DataTable GetScreenHlp()
		{
			DataTable dtHlp = (DataTable)Session[KEY_dtScreenHlp];
			if (dtHlp == null)
			{
				CheckAuthentication(false);
				try
				{
					dtHlp = (new AdminSystem()).GetScreenHlp(2,base.LUser.CultureId,LcSysConnString,LcAppPw);
				}
				catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
				Session[KEY_dtScreenHlp] = dtHlp;
			}
			return dtHlp;
		}

		private void GetGlobalFilter()
		{
			try
			{
				DataTable dt;
				dt = (new AdminSystem()).GetGlobalFilter(base.LUser.UsrId,2,base.LUser.CultureId,LcSysConnString,LcAppPw);
				if (dt != null && dt.Rows.Count > 0)
				{
					cGlobalFilter.Text = dt.Rows[0]["FilterDesc"].ToString();
					cGlobalFilter.Visible = true;
				}
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
		}

		private void GetScreenFilter()
		{
			try
			{
				DataTable dt = (new AdminSystem()).GetScreenFilter(2,base.LUser.CultureId,LcSysConnString,LcAppPw);
				if (dt != null)
				{
					cFilterId.DataSource = dt;
					cFilterId.DataBind();
					if (cFilterId.Items.Count > 0)
					{
						if (Request.QueryString["ftr"] != null) {cFilterId.Items.FindByValue(Request.QueryString["ftr"]).Selected = true;} else {cFilterId.Items[0].Selected = true;}
						cFilterLabel.Text = (new AdminSystem()).GetLabel(base.LUser.CultureId, "QFilter", "QFilter", null, null, null);
						cFilter.Visible = true;
					}
				}
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
		}

		private void GetSystems()
		{
			Session[KEY_sysConnectionString] = LcSysConnString;
			Session[KEY_sysConnectionString + "Pwd"] = LcAppPw;
			DataTable dtSystems = base.SystemsList;
			if (dtSystems != null)
			{
				Session[KEY_dtSystems] = dtSystems;
				cSystemId.DataSource = dtSystems;
				cSystemId.DataBind();
				if (cSystemId.Items.Count > 1)
				{
					if (Request.QueryString["sys"] != null) {cSystemId.Items.FindByValue(Request.QueryString["sys"]).Selected = true;}
					else
					{
						try { cSystemId.Items.FindByValue(base.LCurr.DbId.ToString()).Selected = true; }
						catch {cSystemId.Items[0].Selected = true;}
					}
					base.LCurr.DbId = byte.Parse(cSystemId.SelectedValue);
					Session[KEY_sysConnectionString] = Config.GetConnStr(dtSystems.Rows[cSystemId.SelectedIndex]["dbAppProvider"].ToString(), dtSystems.Rows[cSystemId.SelectedIndex]["ServerName"].ToString(), dtSystems.Rows[cSystemId.SelectedIndex]["dbDesDatabase"].ToString(), "", dtSystems.Rows[cSystemId.SelectedIndex]["dbAppUserId"].ToString());
					Session[KEY_sysConnectionString + "Pwd"] = base.AppPwd(base.LCurr.DbId);
					cSystemLabel.Text = (new AdminSystem()).GetLabel(base.LUser.CultureId, "cSystem", "Label", null, null, null);
					cSystem.Visible = true;
				}
			}
		}

		protected string ColumnWatermark(int idx)
		{
			return GetLabel().Rows[idx]["tbHint"].ToString();
		}
		protected string ColumnHeaderText(int idx)
		{
			return (GetLabel().Rows[idx]["RequiredValid"].ToString() == "Y" ? Config.MandatoryChar : string.Empty)  + GetLabel().Rows[idx]["ColumnHeader"].ToString();
		}
		protected string ColumnToolTip(int idx)
		{
			return GetLabel().Rows[idx]["ToolTip"].ToString();
		}
		protected bool GridColumnVisible(int idx)
		{
			return GetAuthCol().Rows[idx]["ColVisible"].ToString()=="Y";
		}
		protected bool GridColumnEnable(int idx)
		{
			return GetAuthCol().Rows[idx]["ColReadOnly"].ToString()=="N";
		}
		private DataTable GetLabel()
		{
			DataTable dt = (DataTable)Session[KEY_dtLabel];
			if (dt == null)
			{
				try
				{
					dt = (new AdminSystem()).GetScreenLabel(2,base.LUser.CultureId,base.LImpr,base.LCurr,LcSysConnString,LcAppPw);
				}
				catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
				Session[KEY_dtLabel] = dt;
			}
			return dt;
		}

		private DataTable GetAuthCol()
		{
			DataTable dt = (DataTable)Session[KEY_dtAuthCol];
			if (dt == null)
			{
				try
				{
					dt = (new AdminSystem()).GetAuthCol(2,base.LImpr,base.LCurr,LcSysConnString,LcAppPw);
				}
				catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
				Session[KEY_dtAuthCol] = dt;
			}
			return dt;
		}

		protected DataTable GetAuthRow()
		{
			DataTable dt = (DataTable)Session[KEY_dtAuthRow];
			if (dt == null)
			{
				try
				{
					dt = (new AdminSystem()).GetAuthRow(2,base.LImpr.RowAuthoritys,LcSysConnString,LcAppPw);
				}
				catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
				Session[KEY_dtAuthRow] = dt;
			}
			return dt;
		}

		private void getReport(string eExport)
		{
			try
			{
				StringBuilder sb = new StringBuilder();
				CheckAuthentication(false);
				DataView dv = null;
				int filterId = 0; if (Utils.IsInt(cFilterId.SelectedValue)) { filterId = int.Parse(cFilterId.SelectedValue); }
				try
				{
					try {dv = new DataView((new AdminSystem()).GetExp(2,"GetExpAdmDbTable2","Y",(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),filterId,GetScrCriteria(),base.LImpr,base.LCurr,UpdCriteria(false)));}
					catch {dv = new DataView((new AdminSystem()).GetExp(2,"GetExpAdmDbTable2","N",(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),filterId,GetScrCriteria(),base.LImpr,base.LCurr,UpdCriteria(false)));}
				}
				catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
				if (eExport == "TXT")
				{
					DataTable dtAu;
					dtAu = (new AdminSystem()).GetAuthExp(2,base.LUser.CultureId,base.LImpr,base.LCurr,LcSysConnString,LcAppPw);
					if (dtAu != null)
					{
						if (dtAu.Rows[0]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[0]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[1]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[1]["ColumnHeader"].ToString() + (char)9 + dtAu.Rows[1]["ColumnHeader"].ToString() + " Text" + (char)9);}
						if (dtAu.Rows[2]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[2]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[3]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[3]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[4]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[4]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[5]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[5]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[6]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[6]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[15]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[15]["ColumnHeader"].ToString() + (char)9 + dtAu.Rows[15]["ColumnHeader"].ToString() + " Text" + (char)9);}
						if (dtAu.Rows[16]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[16]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[17]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[17]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[18]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[18]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[19]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[19]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[20]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[20]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[21]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[21]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[22]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[22]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[23]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[23]["ColumnHeader"].ToString() + (char)9 + dtAu.Rows[23]["ColumnHeader"].ToString() + " Text" + (char)9);}
						if (dtAu.Rows[24]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[24]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[25]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[25]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[26]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[26]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[27]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[27]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[28]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[28]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[29]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[29]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[30]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[30]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[31]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[31]["ColumnHeader"].ToString() + (char)9);}
						if (dtAu.Rows[32]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[32]["ColumnHeader"].ToString() + (char)9);}
						sb.Append(Environment.NewLine);
					}
					foreach (DataRowView drv in dv)
					{
						if (dtAu.Rows[0]["ColExport"].ToString() == "Y") {sb.Append(RO.Common3.Utils.fmNumeric("0",drv["TableId3"].ToString(),base.LUser.Culture) + (char)9);}
						if (dtAu.Rows[1]["ColExport"].ToString() == "Y") {sb.Append(drv["SystemId3"].ToString() + (char)9 + drv["SystemId3Text"].ToString() + (char)9);}
						if (dtAu.Rows[2]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["TableName3"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						if (dtAu.Rows[3]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["TableDesc3"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						if (dtAu.Rows[4]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["TblObjective3"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						if (dtAu.Rows[5]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["VirtualTbl3"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						if (dtAu.Rows[6]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["MultiDesignDb3"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						if (dtAu.Rows[15]["ColExport"].ToString() == "Y") {sb.Append(drv["ModifiedBy3"].ToString() + (char)9 + drv["ModifiedBy3Text"].ToString() + (char)9);}
						if (dtAu.Rows[16]["ColExport"].ToString() == "Y") {sb.Append(RO.Common3.Utils.fmShortDateTimeUTC(drv["ModifiedOn3"].ToString(),base.LUser.Culture,CurrTimeZoneInfo()) + (char)9);}
						if (dtAu.Rows[17]["ColExport"].ToString() == "Y") {sb.Append(RO.Common3.Utils.fmShortDateTimeUTC(drv["LastSyncDt3"].ToString(),base.LUser.Culture,CurrTimeZoneInfo()) + (char)9);}
						if (dtAu.Rows[18]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["VirtualSql3"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						if (dtAu.Rows[19]["ColExport"].ToString() == "Y") {sb.Append(RO.Common3.Utils.fmNumeric("0",drv["ColumnId5"].ToString(),base.LUser.Culture) + (char)9);}
						if (dtAu.Rows[20]["ColExport"].ToString() == "Y") {sb.Append(RO.Common3.Utils.fmNumeric("0",drv["ColumnIndex5"].ToString(),base.LUser.Culture) + (char)9);}
						if (dtAu.Rows[21]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["ExternalTable5"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						if (dtAu.Rows[22]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["ColumnName5"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						if (dtAu.Rows[23]["ColExport"].ToString() == "Y") {sb.Append(drv["DataType5"].ToString() + (char)9 + drv["DataType5Text"].ToString() + (char)9);}
						if (dtAu.Rows[24]["ColExport"].ToString() == "Y") {sb.Append(RO.Common3.Utils.fmNumeric("0",drv["ColumnLength5"].ToString(),base.LUser.Culture) + (char)9);}
						if (dtAu.Rows[25]["ColExport"].ToString() == "Y") {sb.Append(RO.Common3.Utils.fmNumeric("0",drv["ColumnScale5"].ToString(),base.LUser.Culture) + (char)9);}
						if (dtAu.Rows[26]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["DefaultValue5"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						if (dtAu.Rows[27]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["AllowNulls5"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						if (dtAu.Rows[28]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["ColumnIdentity5"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						if (dtAu.Rows[29]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["PrimaryKey5"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						if (dtAu.Rows[30]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["IsIndexU5"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						if (dtAu.Rows[31]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["IsIndex5"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						if (dtAu.Rows[32]["ColExport"].ToString() == "Y") {sb.Append("\"" + drv["ColObjective5"].ToString().Replace("\"","\"\"") + "\"" + (char)9);}
						sb.Append(Environment.NewLine);
					}
					bExpNow.Value = "Y"; Session["ExportFnm"] = "AdmDbTable.csv"; Session["ExportStr"] = (Config.ExportExcelCSV ? "sep=\t\n": "") + sb.Replace("\r\n","\n");
				}
				else if (eExport == "RTF")
				{
					sb.Append(@"{\rtf1\ansi\ansicpg1252\uc1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f37\fswiss\fcharset0\fprq2{\*\panose 020b0604030504040204}Verdana;}
{\f182\froman\fcharset238\fprq2 Times New Roman CE;}{\f183\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f185\froman\fcharset161\fprq2 Times New Roman Greek;}{\f186\froman\fcharset162\fprq2 Times New Roman Tur;}
{\f187\froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f188\froman\fcharset178\fprq2 Times New Roman (Arabic);}{\f189\froman\fcharset186\fprq2 Times New Roman Baltic;}{\f190\froman\fcharset163\fprq2 Times New Roman (Vietnamese);}
{\f552\fswiss\fcharset238\fprq2 Verdana CE;}{\f553\fswiss\fcharset204\fprq2 Verdana Cyr;}{\f555\fswiss\fcharset161\fprq2 Verdana Greek;}{\f556\fswiss\fcharset162\fprq2 Verdana Tur;}{\f559\fswiss\fcharset186\fprq2 Verdana Baltic;}
{\f560\fswiss\fcharset163\fprq2 Verdana (Vietnamese);}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;
\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{
\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 Normal;}{\*\cs10 \additive \ssemihidden Default Paragraph Font;}{\*
\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv 
\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs20\lang1024\langfe1024\cgrid\langnp1024\langfenp1024 \snext11 \ssemihidden Normal Table;}}{\*\latentstyles\lsdstimax156\lsdlockeddef0}{\*\rsidtbl \rsid1574081\rsid2952683
\rsid4674135\rsid4855636\rsid6620441\rsid6645578\rsid7160396\rsid7497391\rsid8133092\rsid8259185\rsid8528326\rsid8936003\rsid9058410\rsid10305085\rsid10505691\rsid13726773\rsid14047122\rsid14576392\rsid15756354\rsid16472473\rsid16525787}{\*\generator Micr
osoft Word 11.0.6359;}{\info{\title [[ScreenTitle]]}{\author }{\operator }{\creatim\yr2004\mo12\dy21\hr12\min7}{\revtim\yr2004\mo12\dy21\hr16\min16}{\version7}{\edmins5}{\nofpages1}{\nofwords6}{\nofchars38}
{\*\company robocoder corporation}{\nofcharsws43}{\vern24703}}\margl1440\margr1440 \widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\hyphcaps0\formshade\horzdoc\dgmargin\dghspace180\dgvspace180\dghorigin1440\dgvorigin1440
\dghshow1\dgvshow1\jexpand\viewkind1\viewscale100\pgbrdrhead\pgbrdrfoot\splytwnine\ftnlytwnine\htmautsp\nolnhtadjtbl\useltbaln\alntblind\lytcalctblwd\lyttblrtgr\lnbrkrule\nobrkwrptbl\snaptogridincell\allowfieldendsel\wrppunct
\asianbrkrule\rsidroot4855636\newtblstyruls\nogrowautofit \fet0\sectd \linex0\endnhere\sectlinegrid360\sectdefaultcl\sectrsid7497391\sftnbj {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang 
{\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang 
{\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}\pard\plain 
\qc \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid4855636 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\b\fs32\insrsid4855636\charrsid6645578 [[TitleLabel]]}{\b\fs32\insrsid16472473\charrsid6645578 
\par }{\insrsid4855636 
\par }{\b\i\fs18\insrsid4855636\charrsid8936003 [[GlobalFilter]]
\par }\pard \ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid8259185 {\insrsid7497391 
\par }\pard \qc \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid4855636 {\f37\fs16\insrsid4855636\charrsid1574081 [[Grid]]
\par }\pard \ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 {\insrsid4855636 
\par }}");
					sb.Replace("[[TitleLabel]]", cTitleLabel.Text);
					sb.Replace("[[GlobalFilter]]", cGlobalFilter.Text);
					sb.Replace("[[Grid]]", GetRtfGrid(dv));
					bExpNow.Value = "Y"; Session["ExportFnm"] = "AdmDbTable.rtf"; Session["ExportStr"] = sb;
				}
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
		}

		private string GetRtfGrid(DataView dv)
		{
			StringBuilder sb = new StringBuilder("");
			try
			{
				int iColCnt = 0;
				DataTable dtAu;
				dtAu = (new AdminSystem()).GetAuthExp(2,base.LUser.CultureId,base.LImpr,base.LCurr,LcSysConnString,LcAppPw);
				if (dtAu != null)
				{
					if (dtAu.Rows[0]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[1]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[2]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[3]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[4]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[5]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[6]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[15]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[16]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[17]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[18]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[19]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[20]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[21]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[22]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[23]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[24]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[25]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[26]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[27]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[28]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[29]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[30]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[31]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					if (dtAu.Rows[32]["ColExport"].ToString() == "Y") {iColCnt = iColCnt + 1;}
					//Create Header
					sb.Append(@"\trowd \irow0\irowband0\lastrow \ts15\trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 \trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr\brdrs\brdrw10 \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10 ");
					sb.Append(@"\trftsWidth1\trftsWidthB3\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblrsid2981395\tbllkhdrrows\tbllklastrow\tbllkhdrcols\tbllklastcol ");
					sb.Append("\r\n");
					sb.Append(GenCellx(iColCnt));
					sb.Append(@"\pard \ql \li0\ri0\widctlpar\intbl\aspalpha\aspnum\adjustright\rin0\lin0 \lang1033\langfe1033\cgrid\langnp1033\langfenp1033 ");
					sb.Append("\r\n");
					sb.Append(@"\b");
					sb.Append(@"{");
					if (dtAu.Rows[0]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[0]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[1]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[1]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[2]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[2]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[3]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[3]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[4]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[4]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[5]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[5]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[6]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[6]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[15]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[15]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[16]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[16]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[17]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[17]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[18]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[18]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[19]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[19]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[20]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[20]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[21]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[21]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[22]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[22]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[23]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[23]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[24]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[24]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[25]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[25]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[26]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[26]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[27]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[27]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[28]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[28]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[29]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[29]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[30]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[30]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[31]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[31]["ColumnHeader"].ToString() + @"\cell ");}
					if (dtAu.Rows[32]["ColExport"].ToString() == "Y") {sb.Append(dtAu.Rows[32]["ColumnHeader"].ToString() + @"\cell ");}
					sb.Append(@"}");
					sb.Append(@"\b0");
					sb.Append("\r\n");
					sb.Append(@"\pard \ql \li0\ri0\widctlpar\intbl\aspalpha\aspnum\adjustright\rin0\lin0 {");
					sb.Append(@"\insrsid2981395 \trowd \irow0\irowband0\lastrow \ts15\trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 \trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr\brdrs\brdrw10 \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10 ");
					sb.Append(@"\trftsWidth1\trftsWidthB3\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblrsid2981395\tbllkhdrrows\tbllklastrow\tbllkhdrcols\tbllklastcol ");
					sb.Append("\r\n");
					sb.Append(GenCellx(iColCnt));
					sb.Append("\r\n");
					sb.Append(@"\row }");
					sb.Append("\r\n");
				}
				//Create Data Rows
				foreach (DataRowView drv in dv)
				{
					sb.Append(@"\trowd \irow0\irowband0\lastrow \ts15\trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 \trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr\brdrs\brdrw10 \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10 ");
					sb.Append(@"\trftsWidth1\trftsWidthB3\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblrsid2981395\tbllkhdrrows\tbllklastrow\tbllkhdrcols\tbllklastcol ");
					sb.Append("\r\n");
					sb.Append(GenCellx(iColCnt));
					sb.Append(@"\pard \ql \li0\ri0\widctlpar\intbl\aspalpha\aspnum\adjustright\rin0\lin0 \lang1033\langfe1033\cgrid\langnp1033\langfenp1033 ");
					sb.Append("\r\n");
					sb.Append(@"{");
					if (dtAu.Rows[0]["ColExport"].ToString() == "Y") {sb.Append(RO.Common3.Utils.fmNumeric("0",drv["TableId3"].ToString(),base.LUser.Culture) + @"\cell ");}
					if (dtAu.Rows[1]["ColExport"].ToString() == "Y") {sb.Append(drv["SystemId3Text"].ToString() + @"\cell ");}
					if (dtAu.Rows[2]["ColExport"].ToString() == "Y") {sb.Append(drv["TableName3"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					if (dtAu.Rows[3]["ColExport"].ToString() == "Y") {sb.Append(drv["TableDesc3"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					if (dtAu.Rows[4]["ColExport"].ToString() == "Y") {sb.Append(drv["TblObjective3"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					if (dtAu.Rows[5]["ColExport"].ToString() == "Y") {sb.Append(drv["VirtualTbl3"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					if (dtAu.Rows[6]["ColExport"].ToString() == "Y") {sb.Append(drv["MultiDesignDb3"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					if (dtAu.Rows[15]["ColExport"].ToString() == "Y") {sb.Append(drv["ModifiedBy3Text"].ToString() + @"\cell ");}
					if (dtAu.Rows[16]["ColExport"].ToString() == "Y") {sb.Append(RO.Common3.Utils.fmShortDateTimeUTC(drv["ModifiedOn3"].ToString(),base.LUser.Culture,CurrTimeZoneInfo()) + @"\cell ");}
					if (dtAu.Rows[17]["ColExport"].ToString() == "Y") {sb.Append(RO.Common3.Utils.fmShortDateTimeUTC(drv["LastSyncDt3"].ToString(),base.LUser.Culture,CurrTimeZoneInfo()) + @"\cell ");}
					if (dtAu.Rows[18]["ColExport"].ToString() == "Y") {sb.Append(drv["VirtualSql3"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					if (dtAu.Rows[19]["ColExport"].ToString() == "Y") {sb.Append(RO.Common3.Utils.fmNumeric("0",drv["ColumnId5"].ToString(),base.LUser.Culture) + @"\cell ");}
					if (dtAu.Rows[20]["ColExport"].ToString() == "Y") {sb.Append(RO.Common3.Utils.fmNumeric("0",drv["ColumnIndex5"].ToString(),base.LUser.Culture) + @"\cell ");}
					if (dtAu.Rows[21]["ColExport"].ToString() == "Y") {sb.Append(drv["ExternalTable5"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					if (dtAu.Rows[22]["ColExport"].ToString() == "Y") {sb.Append(drv["ColumnName5"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					if (dtAu.Rows[23]["ColExport"].ToString() == "Y") {sb.Append(drv["DataType5Text"].ToString() + @"\cell ");}
					if (dtAu.Rows[24]["ColExport"].ToString() == "Y") {sb.Append(RO.Common3.Utils.fmNumeric("0",drv["ColumnLength5"].ToString(),base.LUser.Culture) + @"\cell ");}
					if (dtAu.Rows[25]["ColExport"].ToString() == "Y") {sb.Append(RO.Common3.Utils.fmNumeric("0",drv["ColumnScale5"].ToString(),base.LUser.Culture) + @"\cell ");}
					if (dtAu.Rows[26]["ColExport"].ToString() == "Y") {sb.Append(drv["DefaultValue5"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					if (dtAu.Rows[27]["ColExport"].ToString() == "Y") {sb.Append(drv["AllowNulls5"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					if (dtAu.Rows[28]["ColExport"].ToString() == "Y") {sb.Append(drv["ColumnIdentity5"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					if (dtAu.Rows[29]["ColExport"].ToString() == "Y") {sb.Append(drv["PrimaryKey5"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					if (dtAu.Rows[30]["ColExport"].ToString() == "Y") {sb.Append(drv["IsIndexU5"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					if (dtAu.Rows[31]["ColExport"].ToString() == "Y") {sb.Append(drv["IsIndex5"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					if (dtAu.Rows[32]["ColExport"].ToString() == "Y") {sb.Append(drv["ColObjective5"].ToString().Replace("\r\n",@"\par ") + @"\cell ");}
					sb.Append(@"}");
					sb.Append("\r\n");
					sb.Append(@"\pard \ql \li0\ri0\widctlpar\intbl\aspalpha\aspnum\adjustright\rin0\lin0 {");
					sb.Append(@"\insrsid2981395 \trowd \irow0\irowband0\lastrow \ts15\trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 \trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr\brdrs\brdrw10 \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10 ");
					sb.Append(@"\trftsWidth1\trftsWidthB3\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblrsid2981395\tbllkhdrrows\tbllklastrow\tbllkhdrcols\tbllklastcol ");
					sb.Append("\r\n");
					sb.Append(GenCellx(iColCnt));
					sb.Append("\r\n");
					sb.Append(@"\row }");
					sb.Append("\r\n");
				}
				sb.Append(@"\pard \par }");
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
			return sb.ToString();
		}

		private StringBuilder GenCellx(int CellCnt)
		{
			StringBuilder sb = new StringBuilder("");
			string strRowPre = @"\clvertalt\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \cltxlrtb\clftsWidth3\clwWidth4428\clshdrawnil ";
			for (int cnt=0; cnt<CellCnt; cnt++) {sb.Append(strRowPre + @"\cellx" + cnt.ToString() + " ");}
			return sb;
		}

		public void cUploadSheetUpl_Click(object sender, System.EventArgs e)
		{
			if (cUploadSheetFi.HasFile && cUploadSheetFi.PostedFile.FileName != string.Empty)
			{
				string pth = "~/data/docs/AdmDbTable_" + LcSystemId.ToString() + "/";
				if (!Directory.Exists(Server.MapPath(pth))) { Directory.CreateDirectory(Server.MapPath(pth)); }
				string fname = pth + Regex.Replace((new FileInfo(cUploadSheetFi.PostedFile.FileName)).Name, "[ #=+]", string.Empty);
				fname = fname.Replace(":","").Replace("..","");
				if (fname != string.Empty)
				{
					if (File.Exists(Server.MapPath(fname))) { (new FileInfo(Server.MapPath(fname))).Delete(); }
					cUploadSheetFi.PostedFile.SaveAs(Server.MapPath(fname));
					cUploadSheetPan.Visible = false; cUploadSheet.Visible = true;
					cUploadSheet.Text = fname; ShowDirty(true); cUploadSheet.Focus();
					cUploadSheet_TextChanged(cUploadSheet, null);
				}
			}
		}

		public void cUploadSheetTgo_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if (cUploadSheet.Visible)
			{
				cUploadSheetPan.Visible = true; cUploadSheet.Visible = false;
			}
			else
			{
				cUploadSheetPan.Visible = false; cUploadSheet.Visible = true;
			}
		}

		public void cDataType5Search_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			DropDownList cc = ((DropDownList)cAdmDbTableGrid.EditItem.FindControl("cDataType5")); Session["Ctrl~/help/DataTypeChart"] = cc.ClientID;
		}

		public void cDataType5Search_Script()
		{
			if (cAdmDbTableGrid.EditIndex > -1 && cAdmDbTableGrid.Items.Count > cAdmDbTableGrid.EditIndex)
			{
				ImageButton ib = (ImageButton)cAdmDbTableGrid.EditItem.FindControl("cDataType5Search");
				if (ib != null)
				{
			    	TextBox pp = ((TextBox)cAdmDbTableGrid.EditItem.FindControl("cColumnId5"));
					DropDownList cc = (DropDownList)cAdmDbTableGrid.EditItem.FindControl("cDataType5");
					string ss = "?dsp=DropDownList"; if (cSystem.Visible) {ss = ss + "&sys=" + cSystemId.SelectedValue;} else {ss = ss + "&sys=3";}
					ib.Attributes["onclick"] = "SearchLink('~/help/DataTypeChart.pdf" + ss + "&typ=N" + "','" + "','',''); return false;";
				}
			}
		}

		public void cExpTxtButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (Before) Web Rule starts here *** //
			getReport("TXT");
			// *** System Button Click (After) Web Rule starts here *** //
		}

		public void cExpRtfButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (before) Web Rule starts here *** //
			getReport("RTF");
			// *** System Button Click (after) Web Rule starts here *** //
		}

		private void GetPageInfo()
		{
			try
			{
				DataTable dt;
				dt = (new AdminSystem()).GetLastPageInfo(2, base.LUser.UsrId, LcSysConnString, LcAppPw);
				cPgSize.Text = dt.Rows[0]["LastPageInfo"].ToString();
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
		}

		public void cClearCriButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (before) Web Rule starts here *** //
			System.Web.UI.WebControls.Calendar cCalendar;
			ListBox cListBox;
			RoboCoder.WebControls.ComboBox cComboBox;
			DropDownList cDropDownList;
			RadioButtonList cRadioButtonList;
			CheckBox cCheckBox;
			TextBox cTextBox;
			DataView dvCri = GetScrCriteria();
			foreach (DataRowView drv in dvCri)
			{
			    if (drv["DisplayName"].ToString() == "ComboBox")	// Reset to page 1 by reassigning the datasource:
			    {
					cComboBox = (RoboCoder.WebControls.ComboBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
					if (cComboBox != null && cComboBox.Items.Count > 0) { cComboBox.DataSource = cComboBox.DataSource; cComboBox.SelectByValue(cComboBox.Items[0].Value, string.Empty, true); }
			    }
			    else if (drv["DisplayName"].ToString() == "DropDownList")
			    {
					cDropDownList = (DropDownList)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
					if (cDropDownList != null && cDropDownList.Items.Count > 0) { cDropDownList.SelectedIndex = 0; }
			    }
			    else if (drv["DisplayName"].ToString() == "ListBox")
			    {
					cListBox = (ListBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
					if (cListBox != null && cListBox.Items.Count > 0) { cListBox.SelectedIndex = 0; }
			    }
			    else if (drv["DisplayName"].ToString() == "RadioButtonList")
			    {
					cRadioButtonList = (RadioButtonList)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
					if (cRadioButtonList != null && cRadioButtonList.Items.Count > 0) { cRadioButtonList.SelectedIndex = 0; }
			    }
			    else if (drv["DisplayName"].ToString() == "Calendar")
			    {
					cCalendar = (System.Web.UI.WebControls.Calendar)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
					if (cCalendar != null)
					{
					    if (drv["RequiredValid"].ToString() == "N") { cCalendar.SelectedDates.Clear(); } else { cCalendar.SelectedDate = System.DateTime.Today; }
					}
			    }
			    else if (drv["DisplayName"].ToString() == "CheckBox")
			    {
					cCheckBox = (CheckBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
					if (cCheckBox != null) { cCheckBox.Checked = false; }
			    }
			    else
			    {
					cTextBox = (TextBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
					if (cTextBox != null)
					{
					    if (drv["RequiredValid"].ToString() == "N") { cTextBox.Text = string.Empty; } else if (drv["DisplayMode"].ToString().IndexOf("Date") >= 0) { cTextBox.Text = System.DateTime.Today.ToString(); } else { cTextBox.Text = "0"; }
					}
			    }
			}
			cCriButton_Click(sender, e);
			if (cFilterId.Items.Count > 0) { cFilterId.SelectedIndex = 0; }
			// *** System Button Click (after) Web Rule starts here *** //
		}

		private void GetCriteria(DataView dvCri)
		{
			try
			{
				DataTable dt;
				dt = (new AdminSystem()).GetLastCriteria(int.Parse(dvCri.Count.ToString()) + 1, 2, 0, base.LUser.UsrId, LcSysConnString, LcAppPw);
				cCriPanel.Visible = true;   // Enable cCriteria.Visible to be set:
				if (dt.Rows.Count <= 0) { cCriteria.Visible = false; }
				if (!string.IsNullOrEmpty(Request.QueryString["key"]) && bUseCri.Value == string.Empty)
				{
					cCriPanel.Visible = false; cClearCriButton.Visible = false;
				}
				else
				{
					cCriPanel.Visible = (cCriteria.Visible && cCriteria.Controls.Count > 2) || cFilter.Visible;
					if ((bool)Session[KEY_bClCriVisible]) {cClearCriButton.Visible = cCriteria.Visible && cCriteria.Controls.Count > 2;} else {cClearCriButton.Visible = false;}
				}
				if (!IsPostBack)
				{
					int jj = 0; // Zero-based to be consistent with SQL reporting.
					foreach (DataRowView drv in dvCri)
					{
						if (Request.QueryString["Cri" + jj.ToString()] != null)
						{
							dt.Rows[jj+1]["LastCriteria"] = Request.QueryString["Cri" + jj.ToString()].ToString();
						}
						jj = jj + 1;
					}
				}
			    SetCriteria(dt, dvCri);
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
		}

		private void GetSelectedItems(ListBox cObj, string selectedItems)
		{
			string selectedItem;
			bool finish;
			if (selectedItems == string.Empty)
			{
				try {cObj.SelectedIndex = 0;} catch {}
			}
			else
			{
				finish = false;
				while (!finish)
				{
					selectedItem = GetSelectedItem(ref selectedItems);
					if (selectedItem == string.Empty) { finish = true; }
					else
					{
						try { cObj.Items.FindByValue(selectedItem).Selected = true; }
						catch { finish = true; try {cObj.SelectedIndex = 0;} catch {} }
					}
				}
			}
		}

		private string GetSelectedItem(ref string selectedItems)
		{
			string selectedItem;
			int sIndex = selectedItems.IndexOf("'");
			int eIndex = selectedItems.IndexOf("'",sIndex + 1);
			if (sIndex >= 0 && eIndex >= 0)
			{
				selectedItem = selectedItems.Substring(sIndex + 1, eIndex - sIndex - 1);
			}
			else
			{
				selectedItem = string.Empty;
			}
			selectedItems = selectedItems.Substring(eIndex + 1, selectedItems.Length - eIndex - 1);
			return selectedItem;
		}

		protected void cCriButton_Click(object sender, System.EventArgs e)
		{
			// *** Criteria Trigger (before) Web Rule starts here *** //
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			if (cAdmDbTableGrid.EditIndex < 0 || (dt != null && UpdateGridRow(sender, new CommandEventArgs("Save", ""))))
			{
			if (IsPostBack && cCriteria.Visible) ReBindCriteria(GetScrCriteria());
			UpdCriteria(true);
			cAdmDbTable2List.ClearSearch(); Session.Remove(KEY_dtAdmDbTable2List);
			PopAdmDbTable2List(sender, e, false, null);
			}
		}

		private void SetCriteria(DataTable dt, DataView dvCri)
		{
			Label cLabel;
			System.Web.UI.WebControls.Calendar cCalendar;
			ListBox cListBox;
			RoboCoder.WebControls.ComboBox cComboBox;
			DropDownList cDropDownList;
			RadioButtonList cRadioButtonList;
			CheckBox cCheckBox;
			TextBox cTextBox;
			DataTable dtCriHlp = GetScreenCriHlp();
			int ii = 1;
			try
			{
				foreach (DataRowView drv in dvCri)
				{
					cLabel = (Label)cCriteria.FindControl("x" + drv["ColumnName"].ToString() + "Label");
					if (drv["DisplayName"].ToString() == "ComboBox")
					{
						cComboBox = (RoboCoder.WebControls.ComboBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
						string val = null; try {val=dt.Rows[ii]["LastCriteria"].ToString();} catch {};
						base.SetCriBehavior(cComboBox, null, cLabel, dtCriHlp.Rows[ii-1]);
						(new AdminSystem()).MkGetScreenIn("2", drv["ScreenCriId"].ToString(), "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString(), LcAppDb, LcDesDb, drv["MultiDesignDb"].ToString(), LcSysConnString, LcAppPw);
						DataView dv = new DataView((new AdminSystem()).GetScreenIn("2", "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString(), (new AdminSystem()).CountScrCri(drv["ScreenCriId"].ToString(), drv["MultiDesignDb"].ToString(), drv["MultiDesignDb"].ToString() == "N" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv["RequiredValid"].ToString(), 0, string.Empty, drv["DisplayMode"].ToString() != "AutoListBox", val, base.LImpr, base.LCurr, drv["MultiDesignDb"].ToString() == "N" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));
						FilterCriteriaDdl(cCriteria, dv, drv);
						cComboBox.DataSource = dv;
						try { cComboBox.SelectByValue(dt.Rows[ii]["LastCriteria"], string.Empty, false); } catch { try { cComboBox.SelectedIndex = 0; } catch { } }
					}
					else if (drv["DisplayName"].ToString() == "DropDownList")
					{
						cDropDownList = (DropDownList)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
						base.SetCriBehavior(cDropDownList, null, cLabel, dtCriHlp.Rows[ii-1]);
						(new AdminSystem()).MkGetScreenIn("2", drv["ScreenCriId"].ToString(), "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString(), LcAppDb, LcDesDb, drv["MultiDesignDb"].ToString(), LcSysConnString, LcAppPw);
						DataView dv = new DataView((new AdminSystem()).GetScreenIn("2", "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString(), (new AdminSystem()).CountScrCri(drv["ScreenCriId"].ToString(), drv["MultiDesignDb"].ToString(), drv["MultiDesignDb"].ToString() == "N" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv["RequiredValid"].ToString(), 0, string.Empty, base.LImpr, base.LCurr, drv["MultiDesignDb"].ToString() == "N" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));
						FilterCriteriaDdl(cCriteria, dv, drv);
						cDropDownList.DataSource = dv;
						cDropDownList.DataBind();
						try { cDropDownList.Items.FindByValue(dt.Rows[ii]["LastCriteria"].ToString()).Selected = true; } catch { try { cDropDownList.SelectedIndex = 0; } catch { } }
					}
					else if (drv["DisplayName"].ToString() == "ListBox")
					{
						cListBox = (ListBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
						string val = null; try {val=dt.Rows[ii]["LastCriteria"].ToString();} catch {};
						base.SetCriBehavior(cListBox, null, cLabel, dtCriHlp.Rows[ii-1]);
						(new AdminSystem()).MkGetScreenIn("2", drv["ScreenCriId"].ToString(), "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString(), LcAppDb, LcDesDb, drv["MultiDesignDb"].ToString(), LcSysConnString, LcAppPw);
						DataView dv = new DataView((new AdminSystem()).GetScreenIn("2", "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString(), (new AdminSystem()).CountScrCri(drv["ScreenCriId"].ToString(), drv["MultiDesignDb"].ToString(), drv["MultiDesignDb"].ToString() == "N" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv["RequiredValid"].ToString(), 0, string.Empty, drv["DisplayMode"].ToString() != "AutoListBox", val, base.LImpr, base.LCurr, drv["MultiDesignDb"].ToString() == "N" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));
						FilterCriteriaDdl(cCriteria, dv, drv);
						cListBox.DataSource = dv;
						cListBox.DataBind();
						GetSelectedItems(cListBox, dt.Rows[ii]["LastCriteria"].ToString());
					}
					else if (drv["DisplayName"].ToString() == "RadioButtonList")
					{
						cRadioButtonList = (RadioButtonList)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
						base.SetCriBehavior(cRadioButtonList, null, cLabel, dtCriHlp.Rows[ii-1]);
						(new AdminSystem()).MkGetScreenIn("2", drv["ScreenCriId"].ToString(), "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString(), LcAppDb, LcDesDb, drv["MultiDesignDb"].ToString(), LcSysConnString, LcAppPw);
						DataView dv = new DataView((new AdminSystem()).GetScreenIn("2", "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString(), (new AdminSystem()).CountScrCri(drv["ScreenCriId"].ToString(), drv["MultiDesignDb"].ToString(), drv["MultiDesignDb"].ToString() == "N" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv["RequiredValid"].ToString(), 0, string.Empty, base.LImpr, base.LCurr, drv["MultiDesignDb"].ToString() == "N" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));
						FilterCriteriaDdl(cCriteria, dv, drv);
						cRadioButtonList.DataSource = dv;
						cRadioButtonList.DataBind();
						try { cRadioButtonList.Items.FindByValue(dt.Rows[ii]["LastCriteria"].ToString()).Selected = true; } catch { try { cRadioButtonList.SelectedIndex = 0; } catch { } }
					}
					else if (drv["DisplayName"].ToString() == "Calendar")
					{
						cCalendar = (System.Web.UI.WebControls.Calendar)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
						base.SetCriBehavior(cCalendar, null, cLabel, dtCriHlp.Rows[ii-1]);
						if (dt.Rows[ii]["LastCriteria"].ToString() == string.Empty)
						{
							cCalendar.SelectedDates.Clear();
						}
						else
						{
							cCalendar.SelectedDate = DateTime.Parse(dt.Rows[ii]["LastCriteria"].ToString()); cCalendar.VisibleDate = cCalendar.SelectedDate;
						}
					}
					else if (drv["DisplayName"].ToString() == "CheckBox")
					{
						cCheckBox = (CheckBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
						base.SetCriBehavior(cCheckBox, null, cLabel, dtCriHlp.Rows[ii-1]);
						if (dt.Rows[ii]["LastCriteria"].ToString() != string.Empty) { cCheckBox.Checked = base.GetBool(dt.Rows[ii]["LastCriteria"].ToString()); }
					}
					else
					{
						cTextBox = (TextBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
						base.SetCriBehavior(cTextBox, null, cLabel, dtCriHlp.Rows[ii-1]);
						cTextBox.Text = dt.Rows[ii]["LastCriteria"].ToString();
					}
					ii = ii + 1;
				}
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
		}

		private void ReBindCriteria(DataView dvCri)
		{
			ListBox cListBox;
			RoboCoder.WebControls.ComboBox cComboBox;
			DropDownList cDropDownList;
			RadioButtonList cRadioButtonList;
			try
			{
				foreach (DataRowView drv in dvCri)
				{
					if (string.IsNullOrEmpty(drv["DdlFtrColumnId"].ToString())  && drv["DisplayMode"].ToString() != "AutoListBox" ) continue;
					if (drv["DisplayName"].ToString() == "ComboBox")
					{
						cComboBox = (RoboCoder.WebControls.ComboBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
						string val = cComboBox.SelectedValue;
						DataView dv = new DataView((new AdminSystem()).GetScreenIn("2", "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString(), (new AdminSystem()).CountScrCri(drv["ScreenCriId"].ToString(), drv["MultiDesignDb"].ToString(), drv["MultiDesignDb"].ToString() == "N" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv["RequiredValid"].ToString(), 0, string.Empty, drv["DisplayMode"].ToString() != "AutoListBox", val, base.LImpr, base.LCurr, drv["MultiDesignDb"].ToString() == "N" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));
						FilterCriteriaDdl(cCriteria, dv, drv);
						cComboBox.DataSource = dv;
						try { cComboBox.SelectByValue(val, string.Empty, false); } catch { try { cComboBox.SelectedIndex = 0; } catch { } }
					}
					else if (drv["DisplayName"].ToString() == "DropDownList")
					{
						cDropDownList = (DropDownList)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
						string val = cDropDownList.SelectedValue;
						DataView dv = new DataView((new AdminSystem()).GetScreenIn("2", "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString(), (new AdminSystem()).CountScrCri(drv["ScreenCriId"].ToString(), drv["MultiDesignDb"].ToString(), drv["MultiDesignDb"].ToString() == "N" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv["RequiredValid"].ToString(), 0, string.Empty, base.LImpr, base.LCurr, drv["MultiDesignDb"].ToString() == "N" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));
						FilterCriteriaDdl(cCriteria, dv, drv);
						cDropDownList.DataSource = dv;
						cDropDownList.DataBind();
						try { cDropDownList.Items.FindByValue(val).Selected = true; } catch { try { cDropDownList.SelectedIndex = 0; } catch { } }
					}
					else if (drv["DisplayName"].ToString() == "ListBox")
					{
						cListBox = (ListBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
						TextBox cTextBox = (TextBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString() + "Hidden");
						string selectedValues = string.Join(",", cListBox.Items.Cast<ListItem>().Where(x => x.Selected).Select(x => "'" + x.Value + "'").ToArray());
						if (drv["DisplayMode"].ToString() == "AutoListBox" && cTextBox != null) selectedValues = cTextBox.Text ;
						DataView dv = new DataView((new AdminSystem()).GetScreenIn("2", "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString(), (new AdminSystem()).CountScrCri(drv["ScreenCriId"].ToString(), drv["MultiDesignDb"].ToString(), drv["MultiDesignDb"].ToString() == "N" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv["RequiredValid"].ToString(), 0, string.Empty, drv["DisplayMode"].ToString() != "AutoListBox", selectedValues, base.LImpr, base.LCurr, drv["MultiDesignDb"].ToString() == "N" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));
						FilterCriteriaDdl(cCriteria, dv, drv);
						cListBox.DataSource = dv;
						cListBox.DataBind();
						GetSelectedItems(cListBox, selectedValues);
					}
					else if (drv["DisplayName"].ToString() == "RadioButtonList")
					{
						cRadioButtonList = (RadioButtonList)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
						string val = cRadioButtonList.SelectedValue;
						DataView dv = new DataView((new AdminSystem()).GetScreenIn("2", "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString(), (new AdminSystem()).CountScrCri(drv["ScreenCriId"].ToString(), drv["MultiDesignDb"].ToString(), drv["MultiDesignDb"].ToString() == "N" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv["RequiredValid"].ToString(), 0, string.Empty, base.LImpr, base.LCurr, drv["MultiDesignDb"].ToString() == "N" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));
						FilterCriteriaDdl(cCriteria, dv, drv);
						cRadioButtonList.DataSource = dv;
						cRadioButtonList.DataBind();
						try { cRadioButtonList.Items.FindByValue(val).Selected = true; } catch { try { cRadioButtonList.SelectedIndex = 0; } catch { } }
					}
				}
			}
			catch { }
		}

		private DataView GetScrCriteria()
		{
		    DataTable dtScrCri = (DataTable)Session[KEY_dtScrCri];
		    if (dtScrCri == null)
		    {
				try
				{
					dtScrCri = (new AdminSystem()).GetScrCriteria("2", LcSysConnString, LcAppPw);
				}
				catch (Exception err) { ErrorTrace(err, "critical"); bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
		        Session[KEY_dtScrCri] = dtScrCri;
		    }
		    return dtScrCri.DefaultView;
		}

		private void MakeScrGrpLab(DataRowView drv)
		{
		    Literal cLiteral = new Literal();
			string sLabelCss = drv["LabelCss"].ToString();
			if (sLabelCss != string.Empty)
			{
				if (sLabelCss.StartsWith(".")) {cLiteral.Text = "<div class=\"" + sLabelCss.Substring(1) + "\">";} else {cLiteral.Text = "<div class=\"r-labelL\" style=\"" + sLabelCss + "\">";}
			}
			else {cLiteral.Text = "<div class=\"r-labelL\">";}
		    cCriteria.Controls.Add(cLiteral);
		    Label cLabel = new Label(); cLabel.ID = "x" + drv["ColumnName"].ToString() + "Label"; cLabel.CssClass = "inp-lbl"; cCriteria.Controls.Add(cLabel);
		    cLiteral = new Literal(); cLiteral.Text = "</div>"; cCriteria.Controls.Add(cLiteral);
		}

		private void MakeScrGrpInp(DataRowView drv)
		{
			System.Web.UI.WebControls.Calendar cCalendar;
			ListBox cListBox;
			RoboCoder.WebControls.ComboBox cComboBox;
			DropDownList cDropDownList;
			RadioButtonList cRadioButtonList;
			CheckBox cCheckBox;
			TextBox cTextBox;
		    Literal cLiteral = new Literal();
			string sContentCss = drv["ContentCss"].ToString();
			if (sContentCss != string.Empty)
			{
				if (sContentCss.StartsWith(".")) {cLiteral.Text = "<div class=\"" + sContentCss.Substring(1) + "\">";} else {cLiteral.Text = "<div class=\"r-content\" style=\"" + sContentCss + "\">";}
			}
			else {cLiteral.Text = "<div class=\"r-content\">";}
		    cCriteria.Controls.Add(cLiteral);
		    if (drv["DisplayName"].ToString() == "ComboBox")
		    {
		        cComboBox = new RoboCoder.WebControls.ComboBox(); cComboBox.ID = "x" + drv["ColumnName"].ToString(); cComboBox.CssClass = "inp-ddl"; cComboBox.SelectedIndexChanged += new EventHandler(cCriButton_Click);
		        cComboBox.DataValueField = drv["DdlKeyColumnName"].ToString(); cComboBox.DataTextField = drv["DdlRefColumnName"].ToString(); cComboBox.AutoPostBack = true;
		        if (drv["DisplayMode"].ToString() == "AutoComplete")
		        {
			        WebControl wcFtr = (WebControl)cCriteria.FindControl("x" + drv["DdlFtrColumnName"].ToString());
		            System.Collections.Generic.Dictionary<string, string> context = new System.Collections.Generic.Dictionary<string, string>();
		            context["method"] = "GetScreenIn";
			        context["addnew"] = "Y";
		            context["sp"] = "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString();
		            context["requiredValid"] = drv["RequiredValid"].ToString();
		            context["mKey"] = drv["DdlKeyColumnName"].ToString();
		            context["mVal"] = drv["DdlRefColumnName"].ToString();
		            context["mTip"] = drv["DdlRefColumnName"].ToString();
		            context["mImg"] = drv["DdlRefColumnName"].ToString();
		            context["ssd"] = Request.QueryString["ssd"];
		            context["scr"] = "2";
		            context["csy"] = "3";
		            context["filter"] = Utils.IsInt(cFilterId.SelectedValue)? cFilterId.SelectedValue : "0";
		            context["isSys"] = "N";
		            context["conn"] = drv["MultiDesignDb"].ToString() == "N" ? string.Empty : KEY_sysConnectionString;
		            context["refColCID"] = wcFtr != null ? wcFtr.ClientID : null;
		            context["refCol"] = wcFtr != null ? drv["DdlFtrColumnName"].ToString() : null;
		            context["refColDataType"] = wcFtr != null ? drv["DdlFtrDataType"].ToString() : null;
		            cComboBox.AutoCompleteUrl = "AutoComplete.aspx/DdlSuggests";
		            cComboBox.DataContext = context;
		            cComboBox.Mode = "A";
		        }
		        cCriteria.Controls.Add(cComboBox);
		    }
		    else if (drv["DisplayName"].ToString() == "DropDownList")
		    {
		        cDropDownList = new DropDownList(); cDropDownList.ID = "x" + drv["ColumnName"].ToString(); cDropDownList.CssClass = "inp-ddl"; cDropDownList.SelectedIndexChanged += new EventHandler(cCriButton_Click);
		        cDropDownList.DataValueField = drv["DdlKeyColumnName"].ToString(); cDropDownList.DataTextField = drv["DdlRefColumnName"].ToString(); cDropDownList.AutoPostBack = true;
		        cCriteria.Controls.Add(cDropDownList);
		    }
		    else if (drv["DisplayName"].ToString() == "ListBox")
		    {
		        cListBox = new ListBox(); cListBox.ID = "x" + drv["ColumnName"].ToString(); cListBox.SelectionMode = ListSelectionMode.Multiple; cListBox.CssClass = "inp-pic"; cListBox.SelectedIndexChanged += new EventHandler(cCriButton_Click);
		        cListBox.DataValueField = drv["DdlKeyColumnName"].ToString(); cListBox.DataTextField = drv["DdlRefColumnName"].ToString(); cListBox.AutoPostBack = true;
		        if (drv["RowSize"].ToString() != string.Empty) {cListBox.Rows = int.Parse(drv["RowSize"].ToString()); cListBox.Height = int.Parse(drv["RowSize"].ToString()) * 16 + 7; }
		        cCriteria.Controls.Add(cListBox);
		        if (drv["DisplayMode"].ToString() == "AutoListBox")
		        {
			        WebControl wcFtr = (WebControl)cCriteria.FindControl("x" + drv["DdlFtrColumnName"].ToString());
		            System.Collections.Generic.Dictionary<string, string> context = new System.Collections.Generic.Dictionary<string, string>();
		            context["method"] = "GetScreenIn";
			        context["addnew"] = "Y";
		            context["sp"] = "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString();
		            context["requiredValid"] = drv["RequiredValid"].ToString();
		            context["mKey"] = drv["DdlKeyColumnName"].ToString();
		            context["mVal"] = drv["DdlRefColumnName"].ToString();
		            context["mTip"] = drv["DdlRefColumnName"].ToString();
		            context["mImg"] = drv["DdlRefColumnName"].ToString();
		            context["ssd"] = Request.QueryString["ssd"];
		            context["scr"] = "2";
		            context["csy"] = "3";
		            context["filter"] = Utils.IsInt(cFilterId.SelectedValue)? cFilterId.SelectedValue : "0";
		            context["isSys"] = "N";
		            context["conn"] = drv["MultiDesignDb"].ToString() == "N" ? string.Empty : KEY_sysConnectionString;
		            context["refColCID"] = wcFtr != null ? wcFtr.ClientID : null;
		            context["refCol"] = wcFtr != null ? drv["DdlFtrColumnName"].ToString() : null;
		            context["refColDataType"] = wcFtr != null ? drv["DdlFtrDataType"].ToString() : null;
		            Session["AdmDbTable2" + cListBox.ID] = context;
		            cListBox.Attributes["ac_context"] = "AdmDbTable2" + cListBox.ID;
		            cListBox.Attributes["ac_url"] = "AutoComplete.aspx/DdlSuggestsEx";
		            cListBox.Attributes["refColCID"] = wcFtr != null ? wcFtr.ClientID : null;
		            cListBox.Attributes["searchable"] = "";
		            TextBox tb = new TextBox(); tb.ID = "x" + drv["ColumnName"].ToString() + "Hidden";tb.Attributes["style"] = "display:none;";
		            cCriteria.Controls.Add(tb);
		        }
		    }
		    else if (drv["DisplayName"].ToString() == "RadioButtonList")
		    {
		        cRadioButtonList = new RadioButtonList(); cRadioButtonList.ID = "x" + drv["ColumnName"].ToString(); cRadioButtonList.CssClass = "inp-rad"; cRadioButtonList.SelectedIndexChanged += new EventHandler(cCriButton_Click);
		        cRadioButtonList.DataValueField = drv["DdlKeyColumnName"].ToString(); cRadioButtonList.DataTextField = drv["DdlRefColumnName"].ToString(); cRadioButtonList.AutoPostBack = true; cRadioButtonList.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
		        cRadioButtonList.Attributes["OnClick"] = "this.focus();";
		        cLiteral = new Literal(); cLiteral.Text = "<div>"; cCriteria.Controls.Add(cLiteral);
		        cCriteria.Controls.Add(cRadioButtonList);
		        cLiteral = new Literal(); cLiteral.Text = "</div>"; cCriteria.Controls.Add(cLiteral);
		    }
		    else if (drv["DisplayName"].ToString() == "Calendar")
		    {
		        cCalendar = new System.Web.UI.WebControls.Calendar(); cCalendar.ID = "x" + drv["ColumnName"].ToString(); cCalendar.CssClass = "inp-txt calendar"; cCalendar.SelectionChanged += new EventHandler(cCriButton_Click); cCriteria.Controls.Add(cCalendar);
		    }
		    else if (drv["DisplayName"].ToString() == "CheckBox")
		    {
		        cCheckBox = new CheckBox(); cCheckBox.ID = "x" + drv["ColumnName"].ToString(); cCheckBox.CssClass = "inp-chk"; cCheckBox.AutoPostBack = true; cCheckBox.CheckedChanged += new EventHandler(cCriButton_Click); cCriteria.Controls.Add(cCheckBox);
		        cCheckBox.Attributes["OnClick"] = "this.focus();";
		    }
		    else
		    {
		        cTextBox = new TextBox(); cTextBox.ID = "x" + drv["ColumnName"].ToString(); cTextBox.CssClass = "inp-txt"; cTextBox.AutoPostBack = true; cTextBox.TextChanged += new EventHandler(cCriButton_Click);
		        if (drv["DisplayMode"].ToString() == "MultiLine") { cTextBox.TextMode = TextBoxMode.MultiLine; }
		        else if (drv["DisplayMode"].ToString() == "Password") { cTextBox.TextMode = TextBoxMode.Password; }
				if (drv["ColumnJustify"].ToString() == "L") { cTextBox.Style.Value = "text-align:left;"; }
				else if (drv["ColumnJustify"].ToString() == "R") { cTextBox.Style.Value = "text-align:right;"; }
				else { cTextBox.Style.Value = "text-align:center;"; }
		        cCriteria.Controls.Add(cTextBox);
		    }
		    cLiteral = new Literal(); cLiteral.Text = "</div>"; cCriteria.Controls.Add(cLiteral);
		}

		private void SetCriHolder(int ii, DataView dvCri)
		{
			Literal cLiteral;
			if (dvCri.Count > 0)
			{
			    foreach (DataRowView drv in dvCri)
			    {
			        cLiteral = new Literal(); cLiteral.Text = "<div class=\"r-criteria\">"; cCriteria.Controls.Add(cLiteral);
			        MakeScrGrpLab(drv);
			        MakeScrGrpInp(drv);
			        cLiteral = new Literal(); cLiteral.Text = "</div>"; cCriteria.Controls.Add(cLiteral);
			    }
			}
		}

		private DataTable MakeColumns(DataTable dt)
		{
		    DataColumnCollection columns = dt.Columns;
		    DataView dvCri = GetScrCriteria();
		    foreach (DataRowView drv in dvCri)
		    {
		        if (drv["DataTypeSysName"].ToString() == "DateTime") { columns.Add(drv["ColumnName"].ToString(), typeof(DateTime)); }
		        else if (drv["DataTypeSysName"].ToString() == "Byte") { columns.Add(drv["ColumnName"].ToString(), typeof(Byte)); }
		        else if (drv["DataTypeSysName"].ToString() == "Int16") { columns.Add(drv["ColumnName"].ToString(), typeof(Int16)); }
		        else if (drv["DataTypeSysName"].ToString() == "Int32") { columns.Add(drv["ColumnName"].ToString(), typeof(Int32)); }
		        else if (drv["DataTypeSysName"].ToString() == "Int64") { columns.Add(drv["ColumnName"].ToString(), typeof(Int64)); }
		        else if (drv["DataTypeSysName"].ToString() == "Single") { columns.Add(drv["ColumnName"].ToString(), typeof(Single)); }
		        else if (drv["DataTypeSysName"].ToString() == "Double") { columns.Add(drv["ColumnName"].ToString(), typeof(Double)); }
		        else if (drv["DataTypeSysName"].ToString() == "Byte[]") { columns.Add(drv["ColumnName"].ToString(), typeof(Byte[])); }
		        else if (drv["DataTypeSysName"].ToString() == "Object") { columns.Add(drv["ColumnName"].ToString(), typeof(Object)); }
		        else { columns.Add(drv["ColumnName"].ToString(), typeof(String)); }
		    }
		    return dt;
		}

		private DataSet UpdCriteria(bool bUpdate)
		{
			System.Web.UI.WebControls.Calendar cCalendar;
			ListBox cListBox;
			RoboCoder.WebControls.ComboBox cComboBox;
			DropDownList cDropDownList;
			RadioButtonList cRadioButtonList;
			CheckBox cCheckBox;
			TextBox cTextBox;
			DataSet ds = new DataSet();
			ds.Tables.Add(MakeColumns(new DataTable("DtScreenIn")));
			DataRow dr = ds.Tables["DtScreenIn"].NewRow();
			DataView dvCri = GetScrCriteria();
			foreach (DataRowView drv in dvCri)
			{
			    if (drv["DisplayName"].ToString() == "ListBox")
			    {
					cListBox = (ListBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
					bool isRequired = drv["RequiredValid"].ToString() == "Y";
					if (cListBox != null)
					{
						int CriCnt = (new AdminSystem()).CountScrCri(drv["ScreenCriId"].ToString(), drv["MultiDesignDb"].ToString(), drv["MultiDesignDb"].ToString() == "N" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId));
						int TotalChoiceCnt = new DataView((new AdminSystem()).GetScreenIn("2", "GetDdl" + drv["ColumnName"].ToString() + LCurr.SystemId.ToString() + "C" + drv["ScreenCriId"].ToString(), CriCnt, drv["RequiredValid"].ToString(), 0, string.Empty, true, string.Empty, base.LImpr, base.LCurr, drv["MultiDesignDb"].ToString() == "N" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId))).Count;
						string selectedValues = string.Join(",", cListBox.Items.Cast<ListItem>().Where(x => x.Selected).Select(x => "'" + x.Value + "'").ToArray());
						bool noneSelected = string.IsNullOrEmpty(selectedValues) || selectedValues == "''";
					    dr[drv["ColumnName"].ToString()] = "(";
					    if (noneSelected && CriCnt+1 > TotalChoiceCnt) dr[drv["ColumnName"].ToString()] = dr[drv["ColumnName"].ToString()].ToString() + "'-1'";
					    foreach (ListItem li in cListBox.Items)
					    {
					        if (li.Selected || (noneSelected && !isRequired && !string.IsNullOrEmpty(li.Value)))
					        {
					            if (dr[drv["ColumnName"].ToString()].ToString() != "(")
					            {
					                dr[drv["ColumnName"].ToString()] = dr[drv["ColumnName"].ToString()].ToString() + ",";
					            }
					            dr[drv["ColumnName"].ToString()] = dr[drv["ColumnName"].ToString()].ToString() + "'" + li.Value + "'";
					        }
					    }
					}
					if (IsPostBack && drv["RequiredValid"].ToString() == "Y" && string.IsNullOrEmpty(cListBox.SelectedValue))
					{
						bErrNow.Value = "Y"; PreMsgPopup("Criteria column: " + drv["ColumnName"].ToString() + " cannot be empty. Please rectify and try again.");
					}
					if (dr[drv["ColumnName"].ToString()].ToString() == "(''" || dr[drv["ColumnName"].ToString()].ToString() == "(") { dr[drv["ColumnName"].ToString()] = string.Empty; } else { dr[drv["ColumnName"].ToString()] = dr[drv["ColumnName"].ToString()].ToString() + ")"; }
			    }
			    else if (drv["DisplayName"].ToString() == "Calendar")
			    {
					cCalendar = (System.Web.UI.WebControls.Calendar)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
					if (cCalendar != null && cCalendar.SelectedDate > DateTime.Parse("0001-01-01")) { dr[drv["ColumnName"].ToString()] = drv["DisplayMode"].ToString() == "CalendarUTC" ? base.SetDateTimeUTC(cCalendar.SelectedDate.ToString("yyyy/MM/dd"), !bUpdate) : cCalendar.SelectedDate.ToString("yyyy/MM/dd"); }
			    }
			    else if (drv["DisplayName"].ToString() == "ComboBox")
			    {
					cComboBox = (RoboCoder.WebControls.ComboBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
					if (IsPostBack && drv["RequiredValid"].ToString() == "Y" && string.IsNullOrEmpty(cComboBox.SelectedValue))
					{
						bErrNow.Value = "Y"; PreMsgPopup("Criteria column: " + drv["ColumnName"].ToString() + " cannot be empty. Please rectify and try again.");
					}
					if (cComboBox != null && cComboBox.SelectedIndex >= 0 && cComboBox.SelectedValue != string.Empty) { dr[drv["ColumnName"].ToString()] = cComboBox.SelectedValue; }
			    }
			    else if (drv["DisplayName"].ToString() == "DropDownList")
			    {
					cDropDownList = (DropDownList)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
					if (IsPostBack && drv["RequiredValid"].ToString() == "Y" && string.IsNullOrEmpty(cDropDownList.SelectedValue))
					{
						bErrNow.Value = "Y"; PreMsgPopup("Criteria column: " + drv["ColumnName"].ToString() + " cannot be empty. Please rectify and try again.");
					}
					if (cDropDownList != null && cDropDownList.SelectedIndex >= 0 && cDropDownList.SelectedValue != string.Empty) { dr[drv["ColumnName"].ToString()] = cDropDownList.SelectedValue; }
			    }
			    else if (drv["DisplayName"].ToString() == "RadioButtonList")
			    {
					cRadioButtonList = (RadioButtonList)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
					if (IsPostBack && drv["RequiredValid"].ToString() == "Y" && string.IsNullOrEmpty(cRadioButtonList.SelectedValue))
					{
						bErrNow.Value = "Y"; PreMsgPopup("Criteria column: " + drv["ColumnName"].ToString() + " cannot be empty. Please rectify and try again.");
					}
					if (cRadioButtonList != null && cRadioButtonList.SelectedIndex >= 0 && cRadioButtonList.SelectedValue != string.Empty) { dr[drv["ColumnName"].ToString()] = cRadioButtonList.SelectedValue; }
			    }
			    else if (drv["DisplayName"].ToString() == "CheckBox")
			    {
					cCheckBox = (CheckBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
					if (cCheckBox != null) { dr[drv["ColumnName"].ToString()] = base.SetBool(cCheckBox.Checked); }
			    }
			    else
			    {
					cTextBox = (TextBox)cCriteria.FindControl("x" + drv["ColumnName"].ToString());
					if (drv["RequiredValid"].ToString() == "Y" && string.IsNullOrEmpty(cTextBox.Text))
					{
						if (IsPostBack) { bErrNow.Value = "Y"; PreMsgPopup("Criteria column: " + drv["ColumnName"].ToString() + " cannot be empty. Please rectify and try again.");}
						cTextBox.Text = drv["DisplayMode"].ToString().Contains("Date") ? DateTime.Today.Date.ToShortDateString() : "?";
					}
					if (cTextBox != null && cTextBox.Text != string.Empty) { dr[drv["ColumnName"].ToString()] = (",DateUTC,DateTimeUTC,ShortDateTimeUTC,LongDateTimeUTC,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0) ? SetDateTimeUTC(cTextBox.Text,!bUpdate) : (drv["DisplayName"].ToString().Contains("Date") ? (DateTime.Parse(cTextBox.Text,System.Threading.Thread.CurrentThread.CurrentCulture).ToString()): cTextBox.Text); }
			    }
			}
			ds.Tables["DtScreenIn"].Rows.Add(dr);
			if (bUpdate) 
			{
				try
				{
					(new AdminSystem()).UpdScrCriteria("2", "AdmDbTable2", dvCri, base.LUser.UsrId, cCriteria.Visible, ds, LcAppConnString, LcAppPw);
				}
				catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
			}
			Session[KEY_dsScrCriVal] = ds;
			return ds;
		}

		private DataTable GetScreenTab()
		{
			CheckAuthentication(false);
			DataTable dtScreenTab = null;
			try
			{
				dtScreenTab = (new AdminSystem()).GetScreenTab(2,base.LUser.CultureId,LcSysConnString,LcAppPw);
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
			return dtScreenTab;
		}

		private void SetSystemId3(DropDownList ddl, string keyId)
		{
			DataTable dt = (DataTable)Session[KEY_dtSystemId3];
			DataView dv = dt != null ? dt.DefaultView : null;
			if (ddl != null)
			{
				string ss = string.Empty;
				ListItem li = null;
				bool bFirst = false;
				bool bAll = false; if (ddl.Enabled && ddl.Visible) {bAll = true;}
				if (dv == null)
				{
					bFirst = true;
					try
					{
						dv = new DataView((new AdminSystem()).GetDdl(2,"GetDdlSystemId3S430",true,bAll,0,keyId,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),string.Empty,base.LImpr,base.LCurr));
					}
					catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
				}
				if (dv != null)
				{
					if (dv.Table.Columns.Contains("TableId"))
					{
						ss = "(TableId is null";
						if (string.IsNullOrEmpty(cAdmDbTable2List.SelectedValue)) {ss = ss + ")";} else {ss = ss + " OR TableId = " + cAdmDbTable2List.SelectedValue + ")";}
					}
					if (!string.IsNullOrEmpty(keyId) && !ddl.Enabled) { ss = ss + (string.IsNullOrEmpty(ss) ? string.Empty : " AND ") + "SystemId3 is not NULL"; }
					dv.RowFilter = ss;
					ddl.DataSource = dv; ddl.DataBind();
					li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}
					else if (!bFirst)
					{
						try
						{
							dv = new DataView((new AdminSystem()).GetDdl(2,"GetDdlSystemId3S430",true,bAll,0,keyId,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),string.Empty,base.LImpr,base.LCurr));
						}
						catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
						dv.RowFilter = ss; ddl.DataSource = dv; ddl.DataBind();
						li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}
					}
					if (dv.Count <= 1 && keyId != string.Empty)	// In case invalid value casued by copy action.
					{
						try
						{
							dv = new DataView((new AdminSystem()).GetDdl(2,"GetDdlSystemId3S430",true,true,0,keyId,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),string.Empty,base.LImpr,base.LCurr));
						}
						catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
						dv.RowFilter = ss; ddl.DataSource = dv; ddl.DataBind();
						li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}
					}
					Session[KEY_dtSystemId3] = dv.Table;
				}
			}
		}

		private void SetSheetNameList(DropDownList ddl, string keyId)
		{
			DataTable dt = (DataTable)Session[KEY_dtSheetNameList];
			DataView dv = dt != null ? dt.DefaultView : null;
			if (ddl != null)
			{
				string ss = string.Empty;
				ListItem li = null;
				bool bFirst = false;
				bool bAll = false; if (ddl.Enabled && ddl.Visible) {bAll = true;}
				if (dv == null)
				{
					bFirst = true;
					try
					{
						dv = new DataView((new AdminSystem()).GetDdl(2,"GetDdlSheetNameList3S4150",true,bAll,0,keyId,LcAppConnString,LcAppPw,string.Empty,base.LImpr,base.LCurr));
					}
					catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
				}
				if (dv != null)
				{
					if (dv.Table.Columns.Contains("TableId"))
					{
						ss = "(TableId is null";
						if (string.IsNullOrEmpty(cAdmDbTable2List.SelectedValue)) {ss = ss + ")";} else {ss = ss + " OR TableId = " + cAdmDbTable2List.SelectedValue + ")";}
					}
					if (!string.IsNullOrEmpty(keyId) && !ddl.Enabled) { ss = ss + (string.IsNullOrEmpty(ss) ? string.Empty : " AND ") + "SheetNameList is not NULL"; }
					dv.RowFilter = ss;
					ddl.DataSource = dv; ddl.DataBind();
					li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}
					else if (!bFirst)
					{
						try
						{
							dv = new DataView((new AdminSystem()).GetDdl(2,"GetDdlSheetNameList3S4150",true,bAll,0,keyId,LcAppConnString,LcAppPw,string.Empty,base.LImpr,base.LCurr));
						}
						catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
						dv.RowFilter = ss; ddl.DataSource = dv; ddl.DataBind();
						li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}
					}
					if (dv.Count <= 1 && keyId != string.Empty)	// In case invalid value casued by copy action.
					{
						try
						{
							dv = new DataView((new AdminSystem()).GetDdl(2,"GetDdlSheetNameList3S4150",true,true,0,keyId,LcAppConnString,LcAppPw,string.Empty,base.LImpr,base.LCurr));
						}
						catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
						dv.RowFilter = ss; ddl.DataSource = dv; ddl.DataBind();
						li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}
					}
					Session[KEY_dtSheetNameList] = dv.Table;
				}
			}
		}

		private void SetModifiedBy3(DropDownList ddl, string keyId)
		{
			DataTable dt = (DataTable)Session[KEY_dtModifiedBy3];
			DataView dv = dt != null ? dt.DefaultView : null;
			if (ddl != null)
			{
				string ss = string.Empty;
				ListItem li = null;
				bool bFirst = false;
				bool bAll = false; if (ddl.Enabled && ddl.Visible) {bAll = true;}
				if (dv == null)
				{
					bFirst = true;
					try
					{
						dv = new DataView((new AdminSystem()).GetDdl(2,"GetDdlModifiedBy3S1451",true,bAll,0,keyId,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),string.Empty,base.LImpr,base.LCurr));
					}
					catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
				}
				if (dv != null)
				{
					if (dv.Table.Columns.Contains("TableId"))
					{
						ss = "(TableId is null";
						if (string.IsNullOrEmpty(cAdmDbTable2List.SelectedValue)) {ss = ss + ")";} else {ss = ss + " OR TableId = " + cAdmDbTable2List.SelectedValue + ")";}
					}
					if (!string.IsNullOrEmpty(keyId) && !ddl.Enabled) { ss = ss + (string.IsNullOrEmpty(ss) ? string.Empty : " AND ") + "ModifiedBy3 is not NULL"; }
					dv.RowFilter = ss;
					ddl.DataSource = dv; ddl.DataBind();
					li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}
					else if (!bFirst)
					{
						try
						{
							dv = new DataView((new AdminSystem()).GetDdl(2,"GetDdlModifiedBy3S1451",true,bAll,0,keyId,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),string.Empty,base.LImpr,base.LCurr));
						}
						catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
						dv.RowFilter = ss; ddl.DataSource = dv; ddl.DataBind();
						li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}
					}
					if (dv.Count <= 1 && keyId != string.Empty)	// In case invalid value casued by copy action.
					{
						try
						{
							dv = new DataView((new AdminSystem()).GetDdl(2,"GetDdlModifiedBy3S1451",true,true,0,keyId,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),string.Empty,base.LImpr,base.LCurr));
						}
						catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
						dv.RowFilter = ss; ddl.DataSource = dv; ddl.DataBind();
						li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}
					}
					Session[KEY_dtModifiedBy3] = dv.Table;
				}
			}
		}

		private void SetDataType5(DropDownList ddl, string keyId)
		{
			DataTable dt = (DataTable)Session[KEY_dtDataType5];
			DataView dv = dt != null ? dt.DefaultView : null;
			if (ddl != null)
			{
				string ss = string.Empty;
				ListItem li = null;
				bool bFirst = false;
				bool bAll = false; if (ddl.Enabled && ddl.Visible) {bAll = true;}
				if (dv == null)
				{
					bFirst = true;
					try
					{
						dv = new DataView((new AdminSystem()).GetDdl(2,"GetDdlDataType3S17",true,bAll,0,keyId,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),string.Empty,base.LImpr,base.LCurr));
					}
					catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
				}
				if (dv != null)
				{
					if (dv.Table.Columns.Contains("TableId"))
					{
						ss = "(TableId is null";
						if (string.IsNullOrEmpty(cAdmDbTable2List.SelectedValue)) {ss = ss + ")";} else {ss = ss + " OR TableId = " + cAdmDbTable2List.SelectedValue + ")";}
					}
					if (!string.IsNullOrEmpty(keyId) && !ddl.Enabled) { ss = ss + (string.IsNullOrEmpty(ss) ? string.Empty : " AND ") + "DataType5 is not NULL"; }
					dv.RowFilter = ss;
					ddl.DataSource = dv; ddl.DataBind();
					li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}
					else if (!bFirst)
					{
						try
						{
							dv = new DataView((new AdminSystem()).GetDdl(2,"GetDdlDataType3S17",true,bAll,0,keyId,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),string.Empty,base.LImpr,base.LCurr));
						}
						catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
						dv.RowFilter = ss; ddl.DataSource = dv; ddl.DataBind();
						li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}
					}
					if (dv.Count <= 1 && keyId != string.Empty)	// In case invalid value casued by copy action.
					{
						try
						{
							dv = new DataView((new AdminSystem()).GetDdl(2,"GetDdlDataType3S17",true,true,0,keyId,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),string.Empty,base.LImpr,base.LCurr));
						}
						catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
						dv.RowFilter = ss; ddl.DataSource = dv; ddl.DataBind();
						li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}
					}
					Session[KEY_dtDataType5] = dv.Table;
				}
			}
		}

		private DataView GetAdmDbTable2List()
		{
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTable2List];
			if (dt == null)
			{
				CheckAuthentication(false);
				int filterId = 0;
				string key = string.Empty;
				if (!string.IsNullOrEmpty(Request.QueryString["key"]) && bUseCri.Value == string.Empty) { key = Request.QueryString["key"].ToString(); }
				else if (Utils.IsInt(cFilterId.SelectedValue)) { filterId = int.Parse(cFilterId.SelectedValue); }
				try
				{
					try {dt = (new AdminSystem()).GetLis(2,"GetLisAdmDbTable2",true,"Y",0,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),filterId,key,string.Empty,GetScrCriteria(),base.LImpr,base.LCurr,UpdCriteria(false));}
					catch {dt = (new AdminSystem()).GetLis(2,"GetLisAdmDbTable2",true,"N",0,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),filterId,key,string.Empty,GetScrCriteria(),base.LImpr,base.LCurr,UpdCriteria(false));}
				}
				catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return new DataView(); }
				dt = SetFunctionality(dt);
			}
			return (new DataView(dt,"","",System.Data.DataViewRowState.CurrentRows));
		}

		private void PopAdmDbTable2List(object sender, System.EventArgs e, bool bPageLoad, object ID)
		{
			DataView dv = GetAdmDbTable2List();
			System.Collections.Generic.Dictionary<string, string> context = new System.Collections.Generic.Dictionary<string, string>();
			context["method"] = "GetLisAdmDbTable2";
			context["mKey"] = "TableId3";
			context["mVal"] = "TableId3Text";
			context["mTip"] = "TableId3Text";
			context["mImg"] = "TableId3Text";
			context["ssd"] = Request.QueryString["ssd"];
			context["scr"] = "2";
			context["csy"] = "3";
			context["filter"] = Utils.IsInt(cFilterId.SelectedValue) && cFilter.Visible ? cFilterId.SelectedValue : "0";
			context["isSys"] = "N";
			context["conn"] = KEY_sysConnectionString;
			cAdmDbTable2List.AutoCompleteUrl = "AutoComplete.aspx/LisSuggests";
			cAdmDbTable2List.DataContext = context;
			if (dv.Table == null) return;
			cAdmDbTable2List.DataSource = dv;
			cAdmDbTable2List.Visible = true;
			if (cAdmDbTable2List.Items.Count <= 0) {cAdmDbTable2List.Visible = false; cAdmDbTable2List_SelectedIndexChanged(sender,e);}
			else
			{
				if (bPageLoad && !string.IsNullOrEmpty(Request.QueryString["key"]) && bUseCri.Value == string.Empty)
				{
					try {cAdmDbTable2List.SelectByValue(Request.QueryString["key"],string.Empty,true);} catch {cAdmDbTable2List.Items[0].Selected = true; cAdmDbTable2List_SelectedIndexChanged(sender, e);}
				    cScreenSearch.Visible = false; cSystem.Visible = false; cEditButton.Visible = true; cSaveCloseButton.Visible = cSaveButton.Visible;
				}
				else
				{
					if (ID != null) {if (!cAdmDbTable2List.SelectByValue(ID,string.Empty,true)) {ID = null;}}
					if (ID == null)
					{
						cAdmDbTable2List_SelectedIndexChanged(sender, e);
					}
				}
			}
		}

		private void SetColumnAuthority()
		{
			DataTable dtAuth = GetAuthCol();
			DataTable dtLabel = GetLabel();
			cTabFolder.CssClass = "TabFolder rmvSpace";
			foreach (DataRow dr in dtAuth.Rows) {if (dr["MasterTable"].ToString() == "Y" && dr["ColVisible"].ToString() == "Y") {cTabFolder.CssClass = "TabFolder"; break;}}
			if (dtAuth != null && dtLabel != null)
			{
				base.SetFoldBehavior(cTableId3, dtAuth.Rows[0], cTableId3P1, cTableId3Label, cTableId3P2, null, dtLabel.Rows[0], null, null, null);
				base.SetFoldBehavior(cSystemId3, dtAuth.Rows[1], cSystemId3P1, cSystemId3Label, cSystemId3P2, null, dtLabel.Rows[1], cRFVSystemId3, null, null);
				base.SetFoldBehavior(cTableName3, dtAuth.Rows[2], cTableName3P1, cTableName3Label, cTableName3P2, null, dtLabel.Rows[2], cRFVTableName3, null, null);
				base.SetFoldBehavior(cTableDesc3, dtAuth.Rows[3], cTableDesc3P1, cTableDesc3Label, cTableDesc3P2, null, dtLabel.Rows[3], cRFVTableDesc3, null, null);
				base.SetFoldBehavior(cTblObjective3, dtAuth.Rows[4], cTblObjective3P1, cTblObjective3Label, cTblObjective3P2, cTblObjective3E, null, dtLabel.Rows[4], null, null, null);
				cTblObjective3E.Attributes["label_id"] = cTblObjective3Label.ClientID; cTblObjective3E.Attributes["target_id"] = cTblObjective3.ClientID;
				base.SetFoldBehavior(cVirtualTbl3, dtAuth.Rows[5], cVirtualTbl3P1, cVirtualTbl3Label, cVirtualTbl3P2, null, dtLabel.Rows[5], null, null, null);
				base.SetFoldBehavior(cMultiDesignDb3, dtAuth.Rows[6], cMultiDesignDb3P1, cMultiDesignDb3Label, cMultiDesignDb3P2, null, dtLabel.Rows[6], null, null, null);
				base.SetFoldBehavior(cModelSample, dtAuth.Rows[7], cModelSampleP1, cModelSampleLabel, cModelSampleP2, null, dtLabel.Rows[7], null, null, null);
				base.SetFoldBehavior(cSyncByDb, dtAuth.Rows[8], cSyncByDbP1, cSyncByDbLabel, cSyncByDbP2, null, dtLabel.Rows[8], null, null, null);
				base.SetFoldBehavior(cAnalToDb, dtAuth.Rows[9], cAnalToDbP1, cAnalToDbLabel, cAnalToDbP2, null, dtLabel.Rows[9], null, null, null);
				base.SetFoldBehavior(cSyncToDb, dtAuth.Rows[10], cSyncToDbP1, cSyncToDbLabel, cSyncToDbP2, null, dtLabel.Rows[10], null, null, null);
				base.SetFoldBehavior(cUploadSheet, dtAuth.Rows[11], cUploadSheetP1, cUploadSheetLabel, cUploadSheetP2, null, dtLabel.Rows[11], null, null, null);
				base.SetFoldBehavior(cSheetNameList, dtAuth.Rows[12], cSheetNameListP1, cSheetNameListLabel, cSheetNameListP2, null, dtLabel.Rows[12], null, null, null);
				base.SetFoldBehavior(cRowsToExamine, dtAuth.Rows[13], cRowsToExamineP1, cRowsToExamineLabel, cRowsToExamineP2, null, dtLabel.Rows[13], null, null, null);
				base.SetFoldBehavior(cBtnScan, dtAuth.Rows[14], null, null, null, dtLabel.Rows[14], null, null, null);
				base.SetFoldBehavior(cModifiedBy3, dtAuth.Rows[15], cModifiedBy3P1, cModifiedBy3Label, cModifiedBy3P2, null, dtLabel.Rows[15], null, null, null);
				base.SetFoldBehavior(cModifiedOn3, dtAuth.Rows[16], cModifiedOn3P1, cModifiedOn3Label, cModifiedOn3P2, null, dtLabel.Rows[16], null, null, null);
				base.SetFoldBehavior(cLastSyncDt3, dtAuth.Rows[17], cLastSyncDt3P1, cLastSyncDt3Label, cLastSyncDt3P2, null, dtLabel.Rows[17], null, null, null);
				base.SetFoldBehavior(cVirtualSql3, dtAuth.Rows[18], cVirtualSql3P1, cVirtualSql3Label, cVirtualSql3P2, cVirtualSql3E, null, dtLabel.Rows[18], null, null, null);
				cVirtualSql3E.Attributes["label_id"] = cVirtualSql3Label.ClientID; cVirtualSql3E.Attributes["target_id"] = cVirtualSql3.ClientID;
			}
			if ((cSystemId3.Attributes["OnChange"] == null || cSystemId3.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cSystemId3.Visible && cSystemId3.Enabled) {cSystemId3.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
			if ((cTableName3.Attributes["OnChange"] == null || cTableName3.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cTableName3.Visible && !cTableName3.ReadOnly) {cTableName3.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
			if ((cTableDesc3.Attributes["OnChange"] == null || cTableDesc3.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cTableDesc3.Visible && !cTableDesc3.ReadOnly) {cTableDesc3.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
			if ((cTblObjective3.Attributes["OnChange"] == null || cTblObjective3.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cTblObjective3.Visible && !cTblObjective3.ReadOnly) {cTblObjective3.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
			if ((cVirtualTbl3.Attributes["OnClick"] == null || cVirtualTbl3.Attributes["OnClick"].IndexOf("ChkPgDirty") < 0) && cVirtualTbl3.Visible && cVirtualTbl3.Enabled) {cVirtualTbl3.Attributes["OnClick"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty(); this.focus();";}
			if ((cMultiDesignDb3.Attributes["OnClick"] == null || cMultiDesignDb3.Attributes["OnClick"].IndexOf("ChkPgDirty") < 0) && cMultiDesignDb3.Visible && cMultiDesignDb3.Enabled) {cMultiDesignDb3.Attributes["OnClick"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty(); this.focus();";}
			if ((cModelSample.Attributes["OnChange"] == null || cModelSample.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cModelSample.Visible && cModelSample.Enabled) {cModelSample.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if ((cSyncByDb.Attributes["OnChange"] == null || cSyncByDb.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cSyncByDb.Visible && cSyncByDb.Enabled) {cSyncByDb.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if ((cAnalToDb.Attributes["OnChange"] == null || cAnalToDb.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cAnalToDb.Visible && cAnalToDb.Enabled) {cAnalToDb.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if ((cSyncToDb.Attributes["OnChange"] == null || cSyncToDb.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cSyncToDb.Visible && cSyncToDb.Enabled) {cSyncToDb.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if ((cUploadSheet.Attributes["OnChange"] == null || cUploadSheet.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cUploadSheet.Visible && !cUploadSheet.ReadOnly) {cUploadSheet.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if ((cSheetNameList.Attributes["OnChange"] == null || cSheetNameList.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cSheetNameList.Visible && cSheetNameList.Enabled) {cSheetNameList.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
			if ((cRowsToExamine.Attributes["OnChange"] == null || cRowsToExamine.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cRowsToExamine.Visible && !cRowsToExamine.ReadOnly) {cRowsToExamine.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
			if ((cModifiedBy3.Attributes["OnChange"] == null || cModifiedBy3.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cModifiedBy3.Visible && cModifiedBy3.Enabled) {cModifiedBy3.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
			if ((cModifiedOn3.Attributes["OnChange"] == null || cModifiedOn3.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cModifiedOn3.Visible && !cModifiedOn3.ReadOnly) {cModifiedOn3.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
			if ((cLastSyncDt3.Attributes["OnChange"] == null || cLastSyncDt3.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cLastSyncDt3.Visible && !cLastSyncDt3.ReadOnly) {cLastSyncDt3.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
			if ((cVirtualSql3.Attributes["OnChange"] == null || cVirtualSql3.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cVirtualSql3.Visible && !cVirtualSql3.ReadOnly) {cVirtualSql3.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
		}

		private DataTable SetFunctionality(DataTable dt)
		{
			DataTable dtAuthRow = GetAuthRow();
			if (dtAuthRow != null)
			{
				DataRow dr = dtAuthRow.Rows[0];
				if (dr["AllowDel"].ToString() == "N" || (Request.QueryString["enb"] != null && Request.QueryString["enb"] == "N"))
				{
					if ((bool)Session[KEY_bDeleteVisible]) {cDeleteButton.Visible = false; Session[KEY_bDeleteVisible] = false;}
				}
				else if ((bool)Session[KEY_bDeleteVisible]) {cDeleteButton.Visible = true; cDeleteButton.Enabled = true;}
				if ((dr["AllowUpd"].ToString() == "N" && dr["AllowAdd"].ToString() == "N") || (Request.QueryString["enb"] != null && Request.QueryString["enb"] == "N"))
				{
					cUndoAllButton.Visible = false; cSaveButton.Visible = false; cSaveCloseButton.Visible = false;
					cShowImpButton.Visible = false;
				}
				else
				{
					cShowImpButton.Visible = dr["ViewOnly"].ToString() != "G";
					if ((bool)Session[KEY_bUndoAllVisible]) {cUndoAllButton.Visible = true; cUndoAllButton.Enabled = true;}
					if ((bool)Session[KEY_bUpdateVisible]) {cSaveButton.Visible = true; cSaveButton.Enabled = true;}
				}
				if ((dr["AllowAdd"].ToString() == "N" && dr["AllowUpd"].ToString() == "N") || dr["ViewOnly"].ToString() == "G" || (Request.QueryString["enb"] != null && Request.QueryString["enb"] == "N")) { cInsRowButton.Visible = false; }
				if (dr["AllowAdd"].ToString() == "N" || (Request.QueryString["enb"] != null && Request.QueryString["enb"] == "N"))
				{
					cNewButton.Visible = false; cNewSaveButton.Visible = false; cCopyButton.Visible = false; cCopySaveButton.Visible = false;
					if (dt != null && dt.Rows.Count > 0) {dt.Rows[0].Delete();}
				}
				else
				{
					if ((bool)Session[KEY_bNewVisible]) {cNewButton.Visible = true; cNewButton.Enabled = true;} else {cNewButton.Visible = false;}
					if ((bool)Session[KEY_bNewSaveVisible]) {cNewSaveButton.Visible = true; cNewSaveButton.Enabled = true;} else {cNewSaveButton.Visible = false;}
					if ((bool)Session[KEY_bCopyVisible]) {cCopyButton.Visible = true; cCopyButton.Enabled = true;} else {cCopyButton.Visible = false;}
					if ((bool)Session[KEY_bCopySaveVisible]) {cCopySaveButton.Visible = true; cCopySaveButton.Enabled = true;} else {cCopySaveButton.Visible = false;}
				}
			}
			return dt;
		}

		protected void cFilterId_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			if (cAdmDbTableGrid.EditIndex < 0 || (dt != null && UpdateGridRow(sender, new CommandEventArgs("Save", ""))))
			{
				cNewButton_Click(sender, new EventArgs());
			}
		}

		protected void cSystemId_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			base.LCurr.DbId = byte.Parse(cSystemId.SelectedValue);
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			if (cAdmDbTableGrid.EditIndex < 0 || (dt != null && UpdateGridRow(sender, new CommandEventArgs("Save", ""))))
			{
				Session[KEY_sysConnectionString] = SysConnectStr(byte.Parse(cSystemId.SelectedValue));
				Session[KEY_sysConnectionString + "Pwd"] = base.AppPwd(base.LCurr.DbId);
				Session.Remove(KEY_dtSystemId3);
				Session.Remove(KEY_dtSheetNameList);
				Session.Remove(KEY_dtModifiedBy3);
				Session.Remove(KEY_dtDataType5);
				GetCriteria(GetScrCriteria());
				cFilterId_SelectedIndexChanged(sender, e);
				cDataType5Search_Script();
			}
		}

		private void ClearMaster(object sender, System.EventArgs e)
		{
			DataTable dt = GetAuthCol();
			if (dt.Rows[1]["ColVisible"].ToString() == "Y" && dt.Rows[1]["ColReadOnly"].ToString() != "Y") {SetSystemId3(cSystemId3,string.Empty);}
			if (dt.Rows[2]["ColVisible"].ToString() == "Y" && dt.Rows[2]["ColReadOnly"].ToString() != "Y") {cTableName3.Text = string.Empty;}
			if (dt.Rows[3]["ColVisible"].ToString() == "Y" && dt.Rows[3]["ColReadOnly"].ToString() != "Y") {cTableDesc3.Text = string.Empty;}
			if (dt.Rows[4]["ColVisible"].ToString() == "Y" && dt.Rows[4]["ColReadOnly"].ToString() != "Y") {cTblObjective3.Text = string.Empty;}
			if (dt.Rows[5]["ColVisible"].ToString() == "Y" && dt.Rows[5]["ColReadOnly"].ToString() != "Y") {cVirtualTbl3.Checked = base.GetBool("N");}
			if (dt.Rows[6]["ColVisible"].ToString() == "Y" && dt.Rows[6]["ColReadOnly"].ToString() != "Y") {cMultiDesignDb3.Checked = base.GetBool("N");}
			if (dt.Rows[7]["ColVisible"].ToString() == "Y" && dt.Rows[7]["ColReadOnly"].ToString() != "Y") {cModelSample.ImageUrl = "~/images/custom/adm/AnalToDb.gif"; }
			if (dt.Rows[8]["ColVisible"].ToString() == "Y" && dt.Rows[8]["ColReadOnly"].ToString() != "Y") {cSyncByDb.ImageUrl = "~/images/custom/adm/SyncByDb.gif"; }
			if (dt.Rows[9]["ColVisible"].ToString() == "Y" && dt.Rows[9]["ColReadOnly"].ToString() != "Y") {cAnalToDb.ImageUrl = "~/images/custom/adm/AnalToDb.gif"; }
			if (dt.Rows[10]["ColVisible"].ToString() == "Y" && dt.Rows[10]["ColReadOnly"].ToString() != "Y") {cSyncToDb.ImageUrl = "~/images/custom/adm/SyncToDb.gif"; }
			if (dt.Rows[11]["ColVisible"].ToString() == "Y" && dt.Rows[11]["ColReadOnly"].ToString() != "Y") {cUploadSheet.Text = string.Empty;}
			if (dt.Rows[12]["ColVisible"].ToString() == "Y" && dt.Rows[12]["ColReadOnly"].ToString() != "Y") {SetSheetNameList(cSheetNameList,string.Empty);}
			if (dt.Rows[13]["ColVisible"].ToString() == "Y" && dt.Rows[13]["ColReadOnly"].ToString() != "Y") {cRowsToExamine.Text = "100";}
			if (dt.Rows[15]["ColVisible"].ToString() == "Y" && dt.Rows[15]["ColReadOnly"].ToString() != "Y") {SetModifiedBy3(cModifiedBy3,string.Empty);}
			if (dt.Rows[16]["ColVisible"].ToString() == "Y" && dt.Rows[16]["ColReadOnly"].ToString() != "Y") {cModifiedOn3.Text = string.Empty;}
			if (dt.Rows[17]["ColVisible"].ToString() == "Y" && dt.Rows[17]["ColReadOnly"].ToString() != "Y") {cLastSyncDt3.Text = string.Empty;}
			if (dt.Rows[18]["ColVisible"].ToString() == "Y" && dt.Rows[18]["ColReadOnly"].ToString() != "Y") {cVirtualSql3.Text = string.Empty;}
			// *** Default Value (Folder) Web Rule starts here *** //
		}

		private void InitMaster(object sender, System.EventArgs e)
		{
			cTableId3.Text = string.Empty;
			SetSystemId3(cSystemId3,string.Empty);
			cTableName3.Text = string.Empty;
			cTableDesc3.Text = string.Empty;
			cTblObjective3.Text = string.Empty;
			cVirtualTbl3.Checked = base.GetBool("N");
			cMultiDesignDb3.Checked = base.GetBool("N");
			cModelSample.ImageUrl = "~/images/custom/adm/AnalToDb.gif";
			cSyncByDb.ImageUrl = "~/images/custom/adm/SyncByDb.gif";
			cAnalToDb.ImageUrl = "~/images/custom/adm/AnalToDb.gif";
			cSyncToDb.ImageUrl = "~/images/custom/adm/SyncToDb.gif";
			cUploadSheet.Text = string.Empty;
			SetSheetNameList(cSheetNameList,string.Empty);
			cRowsToExamine.Text = "100";
			SetModifiedBy3(cModifiedBy3,string.Empty);
			cModifiedOn3.Text = string.Empty;
			cLastSyncDt3.Text = string.Empty;
			cVirtualSql3.Text = string.Empty;
			// *** Default Value (Folder) Web Rule starts here *** //
		}
		protected void cAdmDbTable2List_TextChanged(object sender, System.EventArgs e)
		{
			ScriptManager.GetCurrent(Parent.Page).SetFocus(((RoboCoder.WebControls.ComboBox)sender).FocusID);
		}

		protected void cAdmDbTable2List_DDFindClick(object sender, System.EventArgs e)
		{
			ScriptManager.GetCurrent(Parent.Page).SetFocus(((RoboCoder.WebControls.ComboBox)sender).FocusID);
		}

		protected void cAdmDbTable2List_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			InitMaster(sender, e);      // Do this first to enable defaults for non-database columns.
			DataTable dt = null;
			try
			{
				dt = (new AdminSystem()).GetMstById("GetAdmDbTable2ById",cAdmDbTable2List.SelectedValue,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId));
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
			if (dt != null)
			{
				CheckAuthentication(false);
				if (dt.Rows.Count > 0)
				{
					cAdmDbTable2List.SetDdVisible();
					DataRow dr = dt.Rows[0];
					try {cTableId3.Text = RO.Common3.Utils.fmNumeric("0",dr["TableId3"].ToString(),base.LUser.Culture);} catch {cTableId3.Text = string.Empty;}
					SetSystemId3(cSystemId3,dr["SystemId3"].ToString());
					try {cTableName3.Text = dr["TableName3"].ToString();} catch {cTableName3.Text = string.Empty;}
					try {cTableDesc3.Text = dr["TableDesc3"].ToString();} catch {cTableDesc3.Text = string.Empty;}
					try {cTblObjective3.Text = dr["TblObjective3"].ToString();} catch {cTblObjective3.Text = string.Empty;}
					try {cVirtualTbl3.Checked = base.GetBool(dr["VirtualTbl3"].ToString());} catch {cVirtualTbl3.Checked = false;}
					try {cMultiDesignDb3.Checked = base.GetBool(dr["MultiDesignDb3"].ToString());} catch {cMultiDesignDb3.Checked = false;}
					cModelSample.ImageUrl = "~/images/custom/adm/AnalToDb.gif";
					cSyncByDb.ImageUrl = "~/images/custom/adm/SyncByDb.gif";
					cAnalToDb.ImageUrl = "~/images/custom/adm/AnalToDb.gif";
					cSyncToDb.ImageUrl = "~/images/custom/adm/SyncToDb.gif";
					SetModifiedBy3(cModifiedBy3,dr["ModifiedBy3"].ToString());
					try {cModifiedOn3.Text = RO.Common3.Utils.fmShortDateTimeUTC(dr["ModifiedOn3"].ToString(),base.LUser.Culture,CurrTimeZoneInfo());} catch {cModifiedOn3.Text = string.Empty;}
					try {cLastSyncDt3.Text = RO.Common3.Utils.fmShortDateTimeUTC(dr["LastSyncDt3"].ToString(),base.LUser.Culture,CurrTimeZoneInfo());} catch {cLastSyncDt3.Text = string.Empty;}
					try {cVirtualSql3.Text = dr["VirtualSql3"].ToString();} catch {cVirtualSql3.Text = string.Empty;}
				}
			}
			cButPanel.DataBind(); if (!cSaveButton.Visible) { cInsRowButton.Visible = false; }
			DataTable dtAdmDbTableGrid = null;
			int filterId = 0; if (Utils.IsInt(cFilterId.SelectedValue)) { filterId = int.Parse(cFilterId.SelectedValue); }
			try
			{
				dtAdmDbTableGrid = (new AdminSystem()).GetDtlById(2,"GetAdmDbTable2DtlById",cAdmDbTable2List.SelectedValue,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),filterId,base.LImpr,base.LCurr);
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
			if (!dtAdmDbTableGrid.Columns.Contains("_NewRow")) { dtAdmDbTableGrid.Columns.Add("_NewRow"); }
			Session[KEY_dtAdmDbTableGrid] = dtAdmDbTableGrid;
			cAdmDbTableGrid.EditIndex = -1;
			cAdmDbTableGridDataPager.PageSize = Int16.Parse(cPgSize.Text); GotoPage(0);
			if (Session[KEY_lastSortCol] != null)
			{
				cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs((string)Session[KEY_lastSortExp], SortDirection.Ascending));
			}
			else if (dtAdmDbTableGrid.Rows.Count <= 0 || (!((GetAuthRow().Rows[0]["AllowUpd"].ToString() == "N" || GetAuthRow().Rows[0]["ViewOnly"].ToString() == "G") && GetAuthRow().Rows[0]["AllowAdd"].ToString() == "N") && !(Request.QueryString["enb"] != null && Request.QueryString["enb"] == "N") && dtAdmDbTableGrid.Rows.Count == 1))
			{
				cAdmDbTableGrid_DataBind(dtAdmDbTableGrid.DefaultView);
			}
			cFindButton_Click(sender, e);
			cNaviPanel.Visible = true; cImportPwdPanel.Visible = false; Session.Remove(KEY_scrImport);
			ScriptManager.GetCurrent(Parent.Page).SetFocus(cAdmDbTable2List.FocusID);
			ShowDirty(false); PanelTop.Update();
			//WebRule: Initialization
            HideShowUpload(true);
            if (LCurr.DbId == 3) { cMultiDesignDb3.Enabled = true; } else { cMultiDesignDb3.Enabled = false; }
            /* Automate code table screen creation: */
            if (cTableId3.Text == string.Empty) { 
                cAnalToDb.Style.Add("display","none"); cModelSample.Style.Remove("display");
            }
            else
            {
                cAnalToDb.Style.Remove("display"); cModelSample.Style.Add("display", "none");
                string key = (new RO.WebRules.WebRule()).WrGetScreenId("Ct" + cTableName3.Text, (string)Session[KEY_sysConnectionString], LcAppPw);
                string cid = string.IsNullOrEmpty(key) ? "&cid=" + cTableId3.Text : string.Empty;
                cAnalToDb.Attributes["onclick"] = "if (confirm('Proceed to create/retrieve a grid-only screen for this code table for sure?')) { SearchLink('AdmScreen.aspx?typ=N&ctb=Ct" + cTableName3.Text + cid + "','','',''); return false; }";
            }
			// *** WebRule End *** //
		}

		protected void cModelSample_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			//WebRule: Display the panel to upload spreadsheet with sample data
            if (cUploadSheetP1.Visible) { HideShowUpload(true); } else { HideShowUpload(false); }
			// *** WebRule End *** //
			EnableValidators(true); // Do not remove; Need to reenable after postback, especially in the grid.
		}

		protected void cSyncByDb_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			//WebRule: Synchronize by the physical database
			string tid = cAdmDbTable2List.SelectedValue;
			WebRule wr = new WebRule();
			if (cTableName3.Text == string.Empty) { bErrNow.Value = "Y"; PreMsgPopup("Please enter the table name to synchronize from and try again."); }
			else if (cSystemId3.SelectedValue == string.Empty) { bErrNow.Value = "Y"; PreMsgPopup("Please select the system to synchronize from and try again."); }
			else if (cVirtualTbl3.Checked)
			{
				if (cTableId3.Text == string.Empty) { bErrNow.Value = "Y"; PreMsgPopup("Please add this virtual table first then try again."); }
				else
				{
					string err = wr.WrGetVirtualTbl(tid, base.LCurr.DbId, Session[KEY_sysConnectionString].ToString(), LcAppPw);
					if (err.IndexOf("Error:") >= 0) { bErrNow.Value = "Y"; PreMsgPopup(err); }
					else if (err != string.Empty)
					{
						cVirtualSql3.Text = err;
						cLastSyncDt3.Text = DateTime.Now.ToString("d", new System.Globalization.CultureInfo(base.LUser.Culture)) + " " + DateTime.Now.ToString("hh:mm", new System.Globalization.CultureInfo(base.LUser.Culture));
                        try
                        {
                            SaveDb(sender, new EventArgs());
                            bInfoNow.Value = "Y"; PreMsgPopup("Virtual table synchronized by the table-valued function successfully, please update the individual columns manually.");
                        }
                        catch (Exception er) { bErrNow.Value = "Y"; PreMsgPopup(er.Message); return; }
					}
				}
			}
			else
			{
				tid = wr.WrSyncByDb(LUser.UsrId, byte.Parse(cSystemId3.SelectedValue), byte.Parse(cSystemId.SelectedValue), cTableId3.Text, cTableName3.Text, cTableDesc3.Text, cMultiDesignDb3.Checked, LcSysConnString, LcAppPw);
				if (cTableId3.Text == string.Empty) {Session.Remove(KEY_dtAdmDbTable2List);}
				if (tid.IndexOf("Error:") >= 0) { bErrNow.Value = "Y"; PreMsgPopup(tid); tid = cAdmDbTable2List.SelectedValue; }
				else { bInfoNow.Value = "Y"; PreMsgPopup("Data table and columns synchronized by the physical database successfully."); }
			}
			bPgDirty.Value = "N"; cPgDirty.Style["display"] = "none"; PopAdmDbTable2List(sender, e, false, tid.ToString());
			// *** WebRule End *** //
			EnableValidators(true); // Do not remove; Need to reenable after postback, especially in the grid.
		}

		protected void cAnalToDb_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			// *** On Change/ On Click Web Rule starts here *** //
			EnableValidators(true); // Do not remove; Need to reenable after postback, especially in the grid.
		}

		protected void cSyncToDb_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			//WebRule: Synchronize to the physical database
			string err = string.Empty;
			WebRule wr = new WebRule();
			if (cTableId3.Text == string.Empty) { bErrNow.Value = "Y"; PreMsgPopup("Please select a table to synchronize and try again."); }
			else if (cSystemId3.SelectedValue != cSystemId.SelectedValue) {bErrNow.Value = "Y"; PreMsgPopup("Synchronization to Physical Database is only available to tables defined within its own environment.");}
			else if (cVirtualTbl3.Checked)
			{
				if (cVirtualSql3.Text.Trim() == string.Empty) { bErrNow.Value = "Y"; PreMsgPopup("Please add the SQL to create the desired table-valued function and try again."); }
				else
				{
					DataView dv = new DataView(wr.WrGetDbTableSys(cTableId3.Text, base.LCurr.DbId, Session[KEY_sysConnectionString].ToString(), LcAppPw));
					foreach (DataRowView drv in dv)
					{
						err = wr.WrSyncFunc(cTableName3.Text, cVirtualSql3.Text, Config.GetConnStr(drv["dbProvider"].ToString(), drv["dbServer"].ToString(), drv["dbDatabase"].ToString(), "", drv["dbUserId"].ToString()), LcAppPw);
						if (err != string.Empty) { break; }
					}
					if (err != string.Empty) { bErrNow.Value = "Y"; PreMsgPopup(err); }
					else 
					{
						cLastSyncDt3.Text = DateTime.Now.ToString("d", new System.Globalization.CultureInfo(base.LUser.Culture)) + " " + DateTime.Now.ToString("hh:mm", new System.Globalization.CultureInfo(base.LUser.Culture));
                        try
                        {
                            SaveDb(sender, new EventArgs());
                            bInfoNow.Value = "Y"; PreMsgPopup("Virtual table synchronized to the physical database successfully.");
                        }
                        catch (Exception er) { bErrNow.Value = "Y"; PreMsgPopup(er.Message); return; }
					}
				}
			}
			else
			{
				err = wr.WrSyncToDb(LCurr.DbId, cTableId3.Text, cTableName3.Text, cMultiDesignDb3.Checked, LcSysConnString, LcAppPw);
				if (err != string.Empty) { bErrNow.Value = "Y"; PreMsgPopup(err); }
				else { bInfoNow.Value = "Y"; PreMsgPopup("Data table and columns synchronized to the physical database successfully."); }
			}
			bPgDirty.Value = "N"; cPgDirty.Style["display"] = "none"; PopAdmDbTable2List(sender, e, false, cAdmDbTable2List.SelectedValue);
			// *** WebRule End *** //
			EnableValidators(true); // Do not remove; Need to reenable after postback, especially in the grid.
		}

		protected void cUploadSheet_TextChanged(object sender, System.EventArgs e)
		{
			//WebRule: Upload the worksheets to be scanned
            ScanExcelSample(sender, e, true);
			// *** WebRule End *** //
			EnableValidators(true); // Do not remove; Need to reenable after postback, especially in the grid.
			if (cUploadSheet.Text != string.Empty)
			{
			}
		}

		protected void cBtnScan_Click(object sender, System.EventArgs e)
		{
			//WebRule: Scan spreadsheet
            ScanExcelSample(sender, e, false);
			// *** WebRule End *** //
			EnableValidators(true); // Do not remove; Need to reenable after postback, especially in the grid.
		}

		protected void cDataType5_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			//WebRule: Fill in the length of standard data types
            if (cAdmDbTableGrid.EditIndex > -1 && cAdmDbTableGrid.Items.Count > cAdmDbTableGrid.EditIndex)
            {
                TextBox tb1 = ((TextBox)cAdmDbTableGrid.Items[cAdmDbTableGrid.EditIndex].FindControl("cColumnLength5"));
                TextBox tb2 = ((TextBox)cAdmDbTableGrid.Items[cAdmDbTableGrid.EditIndex].FindControl("cColumnScale5"));
                switch (((DropDownList)sender).SelectedValue)
                {
                    case "1":
                        tb1.Text = "1"; tb1.Enabled = false; tb2.Text = ""; break;
                    case "2":
                        tb1.Text = "2"; tb1.Enabled = false; tb2.Text = ""; break;
                    case "3":
                        tb1.Text = "4"; tb1.Enabled = false; tb2.Text = ""; break;
                    case "6":
                        tb1.Text = "8"; tb1.Enabled = false; tb2.Text = "6"; break;
                    case "18":
                        tb1.Text = "8"; tb1.Enabled = true; tb2.Text = "2"; break;
                    case "4": case "7": case "12": case "21":
                        tb1.Text = "8"; tb1.Enabled = false; tb2.Text = ""; break;
                    default:
                        tb1.Enabled = true; break;
                }
                if (!tb1.Enabled) { tb1.BackColor = System.Drawing.Color.FromName(Config.ReadOnlyBColor); } else { tb1.BackColor = System.Drawing.Color.Empty; }
            }
			// *** WebRule End *** //
			EnableValidators(true);  // Do not remove; Need to reenable after postback, especially in the grid.
			TextBox pwd = null;
			if (cAdmDbTableGrid.EditIndex > -1 && cAdmDbTableGrid.Items.Count > cAdmDbTableGrid.EditIndex)
			{
				if (Session[KEY_dtDataType5] != null)
				{
					DataView dv1 = ((DataTable)Session[KEY_dtDataType5]).DefaultView; dv1.RowFilter = string.Empty;
				}
				DataView dvAdmDbTableGrid = ((DataTable)Session[KEY_dtAdmDbTableGrid]).DefaultView;
				if (Session[KEY_dtDataType5] != null)
				{
					DataView dv3 = ((DataTable)Session[KEY_dtDataType5]).DefaultView;
				}
				Session[KEY_dtAdmDbTableGrid] = dvAdmDbTableGrid.Table;
				cDataType5Search_Script();
			}
			if (pwd != null) {ScriptManager.GetCurrent(Parent.Page).SetFocus(pwd.ClientID);} else {ScriptManager.GetCurrent(Parent.Page).SetFocus(SenderFocusId(sender));}
		}

		public void cFindButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (before) Web Rule starts here *** //
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			DataView dv = dt != null ? dt.DefaultView : null;
			if (dv != null)
			{
				WebControl cc = sender as WebControl;
				if ((cc != null && cc.ID.Equals("cAdmDbTable2List")) || cAdmDbTableGrid.EditIndex < 0 || UpdateGridRow(cAdmDbTableGrid, new CommandEventArgs("Save", "")))
				{
					string rf = string.Empty;
					if (cFind.Text != string.Empty) { rf = "(" + base.GetExpression(cFind.Text.Trim(), GetAuthCol(), 19, cFindFilter.SelectedValue) + ")"; }
					if (rf != string.Empty) { rf = "((" + rf + " or _NewRow = 'Y' ))"; }
					dv.RowFilter = rf;
					ViewState["_RowFilter"] = rf;
					GotoPage(0); cAdmDbTableGrid_DataBind(dv);
					if (GetCurrPageIndex() != (int)Session[KEY_currPageIndex] && (int)Session[KEY_currPageIndex] < GetTotalPages()) { GotoPage((int)Session[KEY_currPageIndex]); cAdmDbTableGrid_DataBind(dv);}
					try {ScriptManager.GetCurrent(Parent.Page).SetFocus(((TextBox)sender).ClientID);} catch {}
				}
			}
			grdCount.InnerText = "(" + RO.Common3.Utils.fmNumeric("0",dv.Count.ToString(),base.LUser.Culture) + " found)";
			// *** System Button Click (after) Web Rule starts here *** //
		}

		public void cFirstButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (before) Web Rule starts here *** //
			GotoPage(0);
			// *** System Button Click (after) Web Rule starts here *** //
		}

		public void cLastButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (before) Web Rule starts here *** //
			GotoPage(GetTotalPages() - 1);
			// *** System Button Click (after) Web Rule starts here *** //
		}

		public void cNextButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (before) Web Rule starts here *** //
			GotoPage(GetCurrPageIndex() + 1);
			// *** System Button Click (after) Web Rule starts here *** //
		}

		public void cPrevButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (before) Web Rule starts here *** //
			GotoPage(GetCurrPageIndex() - 1);
			// *** System Button Click (after) Web Rule starts here *** //
		}

		public void cInsRowButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (before) Web Rule starts here *** //
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			if (dt != null && (ValidPage()) && UpdateGridRow(sender, new CommandEventArgs("Save", "")))
			{
				DataRow dr = dt.NewRow();
				int? sortorder = null;
				dr["AllowNulls5"] = "N";
				dr["ColumnIdentity5"] = "N";
				dr["PrimaryKey5"] = "N";
				dr["IsIndexU5"] = "N";
				dr["IsIndex5"] = "N";
				if (dt.Columns.Contains("_SortOrder"))
				{
				    try
				    {
				        sortorder = 1;
				    } catch {};
				}
				dt.Rows.InsertAt(dr, 0);
				dt.Rows[0]["_NewRow"] = "Y";
				if (sortorder.HasValue) dr["_SortOrder"] = sortorder;
				Session[KEY_lastAddedRow] = 0; Session[KEY_dtAdmDbTableGrid] = dt; Session[KEY_currPageIndex] = 0; GotoPage(0);
				cAdmDbTableGrid_DataBind(dt.DefaultView);
				cAdmDbTableGrid_OnItemEditing(cAdmDbTableGrid, new ListViewEditEventArgs(0));
				// *** Default Value (Grid) Web Rule starts here *** //
			}
			// *** System Button Click (after) Web Rule starts here *** //
		}

		public void cPgSizeButton_Click(object sender, System.EventArgs e)
		{
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			if (cAdmDbTableGrid.EditIndex < 0 || (dt != null && UpdateGridRow(sender, new CommandEventArgs("Save", ""))))
			{
				try {if (int.Parse(cPgSize.Text) < 1 || int.Parse(cPgSize.Text) > 200) {cPgSize.Text = "15";}} catch {cPgSize.Text = "15";}
				cAdmDbTableGridDataPager.PageSize = int.Parse(cPgSize.Text); GotoPage(0);
				if (dt.Rows.Count <= 0 || (!((GetAuthRow().Rows[0]["AllowUpd"].ToString() == "N" || GetAuthRow().Rows[0]["ViewOnly"].ToString() == "G") && GetAuthRow().Rows[0]["AllowAdd"].ToString() == "N") && !(Request.QueryString["enb"] != null && Request.QueryString["enb"] == "N") && dt.Rows.Count == 1)) {cAdmDbTableGrid_DataBind(dt.DefaultView);} else {cFindButton_Click(sender, e);}
				try
				{
					(new AdminSystem()).UpdLastPageInfo(2, base.LUser.UsrId, cPgSize.Text, LcSysConnString, LcAppPw);
				}
				catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); }
			}
		}

		public void cGoto_TextChanged(object sender, System.EventArgs e)
		{
			// *** System Button Click (before) Web Rule starts here *** //
			try {GotoPage(Convert.ToInt32(cGoto.Text) - 1);} catch {} finally {cGoto.Text = (GetCurrPageIndex() + 1).ToString();}
			// *** System Button Click (after) Web Rule starts here *** //
		}

		public void cHideImpButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (before) Web Rule starts here *** //
			cImport.Visible = false; cHideImpButton.Visible = false; cShowImpButton.Visible = (bool)Session[KEY_bShImpVisible];
			cNaviPanel.Visible = true; cImportPwdPanel.Visible = false;
			if ((cShowImpButton.Attributes["OnClick"] == null || cShowImpButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) && cShowImpButton.Visible) {cShowImpButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			// *** System Button Click (after) Web Rule starts here *** //
		}

		public void cShowImpButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (before) Web Rule starts here *** //
			cImport.Visible = true; cShowImpButton.Visible = false; cHideImpButton.Visible = (bool)Session[KEY_bHiImpVisible];
			cNaviPanel.Visible = false; cImportPwdPanel.Visible = false;
			if ((cImportButton.Attributes["OnClick"] == null || cImportButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) && cImportButton.Visible) {cImportButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if ((cHideImpButton.Attributes["OnClick"] == null || cHideImpButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) && cHideImpButton.Visible) {cHideImpButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cSchemaImage.Visible)
			{
				try
				{
					Session["ImportSchema"] = (new AdminSystem()).GetSchemaScrImp(2,base.LUser.CultureId,LcSysConnString,LcAppPw);
				}
				catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
				if (cSchemaImage.Attributes["OnClick"] == null || cSchemaImage.Attributes["OnClick"].IndexOf("ImportSchema.aspx") < 0) {cSchemaImage.Attributes["OnClick"] += "SearchLink('ImportSchema.aspx?scm=S&key=2&csy=3','','',''); return false;";}
			}
			// *** System Button Click (after) Web Rule starts here *** //
		}

		private void ScrImportDdl(DataView dvd, DataRowView drv, bool bComboBox, string PKey, string CKey, string CNam, int MaxLen, string MatchCd, bool bAllowNulls)
		{
			if (dvd != null)
			{
				if (dvd.Table.Columns.Contains(PKey))
				{
					if (string.IsNullOrEmpty(cAdmDbTable2List.SelectedValue))
					{
						dvd.RowFilter = "(" + PKey + " is null)";
					}
					else
					{
						dvd.RowFilter = "(" + PKey + " is null OR " + PKey + " = " + cAdmDbTable2List.SelectedValue + ")";
					}
				}
				bool bFound = false; bool bUnique = true;
				if (!string.IsNullOrEmpty(drv[CKey].ToString().Trim()))   // Always do this first.
				{
					foreach (DataRowView drvd in dvd)
					{
						if (drvd[0].ToString().Trim() == drv[CKey].ToString().Trim()) {drv[CNam] = drvd[1].ToString(); bFound = true; break;}
					}
				}
				if (!string.IsNullOrEmpty(drv[CNam].ToString().Trim()))
				{
					if (drv[CNam].ToString().Length > MaxLen) { drv[CNam] = drv[CNam].ToString().Substring(0,MaxLen); }
					string cnam = drv[CNam].ToString(); object ckey = drv[CKey];	// Saved for reverse later.
					if (!bFound && "2,3,4".IndexOf(MatchCd) >= 0)  // Exact match.
					{
						foreach (DataRowView drvd in dvd)
						{
							if (drvd[1].ToString().Trim().ToLower() == cnam.Trim().ToLower())
							{
								drv[CKey] = drvd[0].ToString();
								if (bComboBox) {drv[CNam] = drvd[1].ToString();}
								if (!bFound) {bFound = true;}
								else { bUnique = false; drv[CNam] = cnam; drv[CKey] = ckey; break; }
							}
							else if (bFound) break;
						}
					}
					if (!bFound && "3,4".IndexOf(MatchCd) >= 0)  // StartsWith.
					{
						foreach (DataRowView drvd in dvd)
						{
							if (drvd[1].ToString().Trim().ToLower().StartsWith(cnam.Trim().ToLower()))
							{
								drv[CKey] = drvd[0].ToString();
								if (bComboBox) {drv[CNam] = drvd[1].ToString();}
								if (!bFound) {bFound = true;}
								else { bUnique = false; drv[CNam] = cnam; drv[CKey] = ckey; break; }
							}
							else if (bFound) break;
						}
					}
					if (!bFound && "4".IndexOf(MatchCd) >= 0)  // Wild search.
					{
						foreach (DataRowView drvd in dvd)
						{
							if (drvd[1].ToString().Trim().ToLower().IndexOf(cnam.Trim().ToLower()) >= 0)
							{
								drv[CKey] = drvd[0].ToString();
								if (bComboBox) {drv[CNam] = drvd[1].ToString();}
								if (!bFound) {bFound = true;}
								else { bUnique = false; drv[CNam] = cnam; drv[CKey] = ckey; break; }
							}
							else if (bFound) break;
						}
					}
					if (!(bFound && bUnique) && MatchCd != "1") {drv[CNam] = "Invalid>" + drv[CNam].ToString(); bErrNow.Value = "Y"; PreMsgPopup("Import has invalid data, please check for \"Invalid>\", rectify and try again.");}
				}
				if (!bFound && !string.IsNullOrEmpty(drv[CKey].ToString()))
				{
					drv[CNam] = "Invalid>" + drv[CKey].ToString(); bErrNow.Value = "Y"; PreMsgPopup("Import has invalid data, please check for \"Invalid>\", rectify and try again.");
				    drv[CKey] = null;
				}
			}
		}

		protected void ScrImport(bool bClear)
		{
			int iRow;
			cNaviPanel.Visible = true; cImportPwdPanel.Visible = false;
			DataTable dti = (DataTable)Session[KEY_scrImport];
			DataTable dtAdmDbTableGrid = (DataTable)Session[KEY_dtAdmDbTableGrid];
			if (dti != null && dtAdmDbTableGrid != null)
			{
				if (bClear)
				{
					dtAdmDbTableGrid.Rows.Clear();
				}
				cFind.Text = string.Empty;
				int iExist = dtAdmDbTableGrid.Rows.Count;
				// Validate dropdown, combobox, etc.
				int jj = 0;
				foreach (DataRowView drv in dti.DefaultView)
				{
					if ((drv.Row.RowState == System.Data.DataRowState.Added || drv.Row.RowState == System.Data.DataRowState.Detached) && jj >= iExist)
					{
						DataTable dtd;
						dtd = (DataTable)Session[KEY_dtDataType5];
						if (dtd == null)
						{
							try
							{
								dtd = (new AdminSystem()).GetDdl(2,"GetDdlDataType3S17",true,true,0,string.Empty,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),string.Empty,base.LImpr,base.LCurr);
							}
							catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
							Session[KEY_dtDataType5] = dtd;
						}
						ScrImportDdl(dtd.DefaultView, drv, false, "TableId", "DataType5", "DataType5Text", 20, "2", false);
					}
					jj = jj + 1;
				}
				iRow = dti.DefaultView.Count - iExist;
				if (!dti.Columns.Contains("_NewRow")) { dti.Columns.Add("_NewRow"); }
				Session[KEY_dtAdmDbTableGrid] = dti;
				cAdmDbTableGrid_DataBind(dti.DefaultView);
				string msg = iRow.ToString() + " rows from selected source imported successfully. " + Session[KEY_cntImpPwdOvride].ToString() + " rows validated by Password Override. Please press Save button to save to database.";
				if (Session["CtrlAcctList"] != null)
				{
					System.Collections.Hashtable ht = (System.Collections.Hashtable) Session["CtrlAcctList"];
					string ss = string.Empty;
					System.Collections.IDictionaryEnumerator de = ht.GetEnumerator();
					while ( de.MoveNext() )
					{
						ss = ss + de.Key + " (" + de.Value.ToString() + "), ";
					}
					msg = msg + " List of Password Override items: " + ss.Remove(ss.Length - 2, 2) + ".";
				}
				Session.Remove(KEY_scrImport); Session.Remove("CtrlAcctList");
				cImportPwd.Text = string.Empty;
				ShowDirty(true);
				Session[KEY_lastImpPwdOvride] = 0; Session[KEY_cntImpPwdOvride] = 0;
				bInfoNow.Value = "Y"; PreMsgPopup(msg);
			}
		}

		public void cContinueButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (before) Web Rule starts here *** //
			ScrImport(false);
			// *** System Button Click (after) Web Rule starts here *** //
		}

		protected void cBrowseButton_Click(object sender, EventArgs e)
		{
			if (cBrowse.HasFile && cBrowse.PostedFile.FileName != string.Empty)
			{
				string fileAndPath = cBrowse.PostedFile.FileName;
				string fNameO = string.Empty;
				try {
				    foreach (var c in Path.GetInvalidPathChars()) { fileAndPath = fileAndPath.Replace(c, '_'); }
				    fNameO = Path.GetFileName(fileAndPath);
				}
				catch (Exception err) {
				    bErrNow.Value = "Y"; PreMsgPopup("Invalid characters in file and/or path \"" + fileAndPath + "\": " + err.Message);
				    return;
				}
				try {
					string fName;
					if (fNameO.LastIndexOf(".") >= 0)
					{
						fName = fNameO.Insert(fNameO.LastIndexOf("."), "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString());
					}
					else
					{
						fName = fNameO + "_" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
					}
					fName = fName.Replace(":","").Replace("..","");
					if (!Directory.Exists(Config.PathTmpImport)) { Directory.CreateDirectory(Config.PathTmpImport); }
					cBrowse.PostedFile.SaveAs(Config.PathTmpImport + fName);
					cWorkSheet.DataSource = (new XLSImport(Config.WsXlsUrl)).GetSheetNames(Config.PathTmpImport + fName); cWorkSheet.DataBind();
					cFNameO.Text = fNameO; cFName.Text = fName;
				}
				catch (Exception err) {bErrNow.Value = "Y"; PreMsgPopup("Unable to retrieve sheet names from \"" + fNameO + "\": " + err.Message); }
			}
		}

		public void cImportButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (Before) Web Rule starts here *** //
			if (cFNameO.Text != string.Empty && cWorkSheet.Items.Count > 0 && cWorkSheet.SelectedItem.Text != string.Empty && cStartRow.Text != string.Empty)
			{
				DataTable dtAdmDbTableGrid = (DataTable)Session[KEY_dtAdmDbTableGrid];
				try
				{
					if (cAdmDbTableGrid.EditIndex < 0 || UpdateGridRow(cAdmDbTableGrid, new CommandEventArgs("Save", "")))
					{
						Session[KEY_scrImport] = ImportFile(dtAdmDbTableGrid.Copy(),cFNameO.Text,cWorkSheet.SelectedItem.Text,cStartRow.Text,Config.PathTmpImport + cFName.Text);
					}
					cHideImpButton_Click(sender,new EventArgs());
				}
				catch (Exception err) {bErrNow.Value = "Y"; PreMsgPopup("Error in spreadsheet \"" + cFNameO.Text + "\":<br>" + err.Message); return; }
				finally {cWorkSheet.Items.Clear();}
				ScrImport(false);
			}
			else
			{
				bInfoNow.Value = "Y"; PreMsgPopup("Please select a spreadsheet, then a worksheet, indicate the starting row and try again.");
			}
			// *** System Button Click (After) Web Rule starts here *** //
		}

		private DataTable ImportFile(DataTable dt, string fileName, string workSheet, string startRow, string fileFullName)
		{
			try
			{
				DataTable dtImp = RO.Common3.XmlUtils.XmlToDataSet((new XLSImport(Config.WsXlsUrl)).ImportFile(fileName,workSheet,startRow,fileFullName)).Tables[0];
				DataRowCollection rows = dtImp.Rows;
				DataColumnCollection cols = dt.Columns;
				Func<string, string, bool> isDateCol = (cl, c) => ("," + cl + ",").IndexOf("," + c + ",") >= 0;
				Func<string, string, bool> isDateUTCCol = (cl, c) => ("," + cl + ",").IndexOf("," + c + ",") >= 0;
				string ss;
				int iStart = int.Parse(startRow) - 1;
				int idv = dt.Rows.Count;
				int idel = 0;
				System.Collections.Generic.List<string> ErrLst = new System.Collections.Generic.List<string>();
				bool bHasErr = false;
				for ( int iRow = iStart; iRow < rows.Count; iRow++ )
				{
					if (rows[iRow][3].ToString() == string.Empty && rows[iRow][4].ToString() == string.Empty && rows[iRow][5].ToString() == string.Empty && rows[iRow][6].ToString() == string.Empty && rows[iRow][9].ToString() == string.Empty && rows[iRow][10].ToString() == string.Empty && rows[iRow][11].ToString() == string.Empty && rows[iRow][12].ToString() == string.Empty && rows[iRow][13].ToString() == string.Empty) {idel = idel + 1;}
					else
					{
						dt.Rows.Add(dt.NewRow());
						if (rows[iRow][9].ToString() == string.Empty) { rows[iRow][9] = "N";}
						if (rows[iRow][10].ToString() == string.Empty) { rows[iRow][10] = "N";}
						if (rows[iRow][11].ToString() == string.Empty) { rows[iRow][11] = "N";}
						if (rows[iRow][12].ToString() == string.Empty) { rows[iRow][12] = "N";}
						if (rows[iRow][13].ToString() == string.Empty) { rows[iRow][13] = "N";}
						for ( int iCol = 0; iCol < cols.Count; iCol++ )
						{
							try { ss = rows[iRow][iCol].ToString().Trim(); } catch { ss = string.Empty; }
							try {
							    if (!string.IsNullOrEmpty(ss)) {
							        dt.Rows[iRow - iStart - idel + idv][iCol] = isDateCol("", iCol.ToString()) ? base.ToIntDateTime(ss, isDateUTCCol("", iCol.ToString()), true) : ss;
							    }
							}
							catch (Exception ex) {
							    if (ss.EndsWith("%")) {
							        try { dt.Rows[iRow - iStart - idel + idv][iCol] = ss.Left(ss.Length - 1); } catch { }
							    }
							    else {
							        bHasErr = true;
							        ErrLst.Add("Row " + (iRow + 1).ToString() + " Col " + Utils.Num2ExcelCol(iCol + 1) + ": " + Server.HtmlEncode(ex.Message));
							    }
							}
						}
					}
				}
				if (bHasErr) { throw new Exception(string.Join("<br>", ErrLst)); }
			}
			catch(Exception e) { throw (e); }
			return dt;
		}

		private void GotoPage(int pageNo)
		{
			if (pageNo >= 0 && pageNo < GetTotalPages())
			{
				if (cAdmDbTableGrid.EditIndex < 0 || UpdateGridRow(cAdmDbTableGrid, new CommandEventArgs("Save", "")))
				{
					try { cAdmDbTableGridDataPager.SetPageProperties(cAdmDbTableGridDataPager.PageSize * pageNo, cAdmDbTableGridDataPager.MaximumRows, false); cAdmDbTableGrid_DataBind(null); }
					catch
					{
						try { cAdmDbTableGridDataPager.SetPageProperties(0, cAdmDbTableGridDataPager.MaximumRows, false); cAdmDbTableGrid_DataBind(null); } catch {}
					}
				}
			}
		}

		protected void cAdmDbTableGrid_OnItemCommand(object sender, ListViewCommandEventArgs e)
		{
		}

		private void cAdmDbTableGrid_DataBind(DataView dvAdmDbTableGrid)
		{
			if (dvAdmDbTableGrid == null)
			{
				DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
				dvAdmDbTableGrid = dt != null ? dt.DefaultView : null;
			}
			if (dvAdmDbTableGrid != null)
			{
				LcAuth = GetAuthCol().AsEnumerable().ToDictionary<DataRow,string>(dr=>dr["ColName"].ToString());
				cAdmDbTableGrid.DataSource = dvAdmDbTableGrid;
				cAdmDbTableGrid.DataBind();
				int totalPages = GetTotalPages(); if (totalPages <= 0) { totalPages = 1; }
				cPageNoLabel.Text = " of " + totalPages.ToString(); cGoto.Text = (GetCurrPageIndex() + 1).ToString();
			}
			if (cFindFilter.Items.Count <= 0)
			{
				DataTable dtAuth = GetAuthCol();
				DataTable dtLabel = GetLabel();
				int ii = 0;
				ListItem li = new ListItem();
				li.Value = string.Empty; li.Text = "All";
				cFindFilter.Items.Add(li);
				foreach (DataRow dr in dtLabel.Rows)
				{
					if (ii >= 19 && !string.IsNullOrEmpty(dr["ColumnHeader"].ToString()) && !string.IsNullOrEmpty(dr["TableId"].ToString()) && dtAuth.Rows[ii]["ColVisible"].ToString() == "Y")
					{
						li = new ListItem();
						li.Value = ii.ToString(); li.Text = dr["ColumnHeader"].ToString().Replace("*", string.Empty);
						cFindFilter.Items.Add(li);
					}
					ii = ii + 1;
				}
			}
		}

		protected void cAdmDbTableGrid_OnSorting(object sender, ListViewSortEventArgs e)
		{
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			DataView dv = dt != null ? dt.DefaultView : null;
			if (dv != null)
			{
				if (cAdmDbTableGrid.EditIndex < 0 || UpdateGridRow(cAdmDbTableGrid, new CommandEventArgs("Save", "")))
				{
					string ftr = string.Empty;
					if (!dv.Table.Columns.Contains("_SortOrder")) { dv.Table.Columns.Add("_SortOrder"); }
					if (dv.RowFilter != string.Empty) { ftr = dv.RowFilter; dv.RowFilter = string.Empty; }
					if (Session[KEY_lastSortUrl] == null)   // First time.
					{
					    dv.Sort = "_SortOrder DESC, " + e.SortExpression; Session[KEY_lastSortUrl] = "~/images/ArrowUp.png"; Session[KEY_lastSortTog] = "N";
					}
					else if ((string)Session[KEY_lastSortTog] == "Y")
					{
					    if (((string)Session[KEY_lastSortUrl]).IndexOf("ArrowDn") >= 0)
					    {
							dv.Sort = "_SortOrder DESC, " + e.SortExpression; Session[KEY_lastSortUrl] = "~/images/ArrowUp.png";
					    }
					    else
					    {
							dv.Sort = "_SortOrder DESC, " + e.SortExpression + " DESC"; Session[KEY_lastSortUrl] = "~/images/ArrowDn.png";
					    }
					    Session[KEY_lastSortTog] = "N";
					}
					else if (((string)Session[KEY_lastSortUrl]).IndexOf("ArrowDn") >= 0) { dv.Sort = "_SortOrder DESC, " + e.SortExpression + " DESC"; } else { dv.Sort = "_SortOrder DESC, " + e.SortExpression; }
					ViewState["_SortColumn"] = dv.Sort;
					if (ftr != string.Empty) { dv.RowFilter = ftr; }
					Session[KEY_dtAdmDbTableGrid] = dt;
					cAdmDbTableGrid_DataBind(dv);
				}
			}
		}

		protected void cAdmDbTableGrid_OnPagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
		{
		    cAdmDbTableGridDataPager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
		    DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
		    DataView dv = dt != null ? dt.DefaultView : null;
			cAdmDbTableGrid_DataBind(dv); cAdmDbTableGrid.EditIndex = -1;
		}

		private void GridChkPgDirty(ListViewItem lvi)
		{
				WebControl cc = null;
				cc = ((WebControl)lvi.FindControl("cColumnIndex5"));
				if ((cc.Attributes["OnChange"] == null || cc.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cc.Visible && cc.Enabled) {cc.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
				cc = ((WebControl)lvi.FindControl("cExternalTable5"));
				if ((cc.Attributes["OnChange"] == null || cc.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cc.Visible && cc.Enabled) {cc.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
				cc = ((WebControl)lvi.FindControl("cColumnName5"));
				if ((cc.Attributes["OnChange"] == null || cc.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cc.Visible && cc.Enabled) {cc.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
				cc = ((WebControl)lvi.FindControl("cDataType5"));
				if ((cc.Attributes["OnChange"] == null || cc.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cc.Visible && cc.Enabled) {cc.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty(); document.getElementById('" + bConfirm.ClientID + "').value='N';";}
				cc = ((WebControl)lvi.FindControl("cDataType5Search"));
				if (cc.Attributes["OnClick"] == null || cc.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cc.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
				cc = ((WebControl)lvi.FindControl("cColumnLength5"));
				if ((cc.Attributes["OnChange"] == null || cc.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cc.Visible && cc.Enabled) {cc.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
				cc = ((WebControl)lvi.FindControl("cColumnScale5"));
				if ((cc.Attributes["OnChange"] == null || cc.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cc.Visible && cc.Enabled) {cc.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
				cc = ((WebControl)lvi.FindControl("cDefaultValue5"));
				if ((cc.Attributes["OnChange"] == null || cc.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cc.Visible && cc.Enabled) {cc.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
				cc = ((WebControl)lvi.FindControl("cAllowNulls5"));
				if ((cc.Attributes["OnClick"] == null || cc.Attributes["OnClick"].IndexOf("ChkPgDirty") < 0) && cc.Visible && cc.Enabled) {cc.Attributes["OnClick"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty(); this.focus();";}
				cc = ((WebControl)lvi.FindControl("cColumnIdentity5"));
				if ((cc.Attributes["OnClick"] == null || cc.Attributes["OnClick"].IndexOf("ChkPgDirty") < 0) && cc.Visible && cc.Enabled) {cc.Attributes["OnClick"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty(); this.focus();";}
				cc = ((WebControl)lvi.FindControl("cPrimaryKey5"));
				if ((cc.Attributes["OnClick"] == null || cc.Attributes["OnClick"].IndexOf("ChkPgDirty") < 0) && cc.Visible && cc.Enabled) {cc.Attributes["OnClick"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty(); this.focus();";}
				cc = ((WebControl)lvi.FindControl("cIsIndexU5"));
				if ((cc.Attributes["OnClick"] == null || cc.Attributes["OnClick"].IndexOf("ChkPgDirty") < 0) && cc.Visible && cc.Enabled) {cc.Attributes["OnClick"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty(); this.focus();";}
				cc = ((WebControl)lvi.FindControl("cIsIndex5"));
				if ((cc.Attributes["OnClick"] == null || cc.Attributes["OnClick"].IndexOf("ChkPgDirty") < 0) && cc.Visible && cc.Enabled) {cc.Attributes["OnClick"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty(); this.focus();";}
				cc = ((WebControl)lvi.FindControl("cColObjective5"));
				if ((cc.Attributes["OnChange"] == null || cc.Attributes["OnChange"].IndexOf("ChkPgDirty") < 0) && cc.Visible && cc.Enabled) {cc.Attributes["OnChange"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty();";}
		}

		protected void cAdmDbTableGrid_OnItemDataBound(object sender, ListViewItemEventArgs e)
		{
			// *** GridItemDataBound (before) Web Rule End *** //
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			bool isEditItem = false;
			DataView dvAdmDbTableGrid = dt != null ? dt.DefaultView : null;
			if (cAdmDbTableGrid.EditIndex > -1 && GetDataItemIndex(cAdmDbTableGrid.EditIndex) == e.Item.DataItemIndex)
			{
				isEditItem = true;
				base.SetGridEnabled(e.Item, GetAuthCol(), GetLabel(), 19);
				SetDataType5((DropDownList)e.Item.FindControl("cDataType5"),dvAdmDbTableGrid[e.Item.DataItemIndex]["DataType5"].ToString());
				CheckBox cb = null;
				cb = (CheckBox)e.Item.FindControl("cAllowNulls5");
				if (cb != null)
				{
					cb.Checked = base.GetBool(dvAdmDbTableGrid[e.Item.DataItemIndex]["AllowNulls5"].ToString());
				}
				cb = (CheckBox)e.Item.FindControl("cColumnIdentity5");
				if (cb != null)
				{
					cb.Checked = base.GetBool(dvAdmDbTableGrid[e.Item.DataItemIndex]["ColumnIdentity5"].ToString());
				}
				cb = (CheckBox)e.Item.FindControl("cPrimaryKey5");
				if (cb != null)
				{
					cb.Checked = base.GetBool(dvAdmDbTableGrid[e.Item.DataItemIndex]["PrimaryKey5"].ToString());
				}
				cb = (CheckBox)e.Item.FindControl("cIsIndexU5");
				if (cb != null)
				{
					cb.Checked = base.GetBool(dvAdmDbTableGrid[e.Item.DataItemIndex]["IsIndexU5"].ToString());
				}
				cb = (CheckBox)e.Item.FindControl("cIsIndex5");
				if (cb != null)
				{
					cb.Checked = base.GetBool(dvAdmDbTableGrid[e.Item.DataItemIndex]["IsIndex5"].ToString());
				}
				GridChkPgDirty(e.Item);
			}
			SetClientRule((ListViewDataItem) e.Item,isEditItem);
			DataTable dtAuthRow = GetAuthRow();
			if (dtAuthRow != null)
			{
				DataRow dr = dtAuthRow.Rows[0];
			    Control cc = null;
				if (!CanAct('S') || dr["ViewOnly"].ToString() == "G" || (Request.QueryString["enb"] != null && Request.QueryString["enb"] == "N"))
				{
					cc = e.Item.FindControl("cAdmDbTableGridDelete"); if (cc != null) { cc.Visible = false; }
					cc = e.Item.FindControl("cAdmDbTableGridEdit"); if (cc != null) { cc.Visible = false; }
				}
				else
				{
			        HtmlTableRow tr = e.Item.FindControl("cAdmDbTableGridRow") as HtmlTableRow;
			        LinkButton lb = e.Item.FindControl("cAdmDbTableGridEdit") as LinkButton;
			        if (tr != null && lb != null) { SetDefaultCtrl(tr, lb, string.Empty); }
				}
			}
			if (cAdmDbTableGrid.EditIndex > -1 && GetDataItemIndex(cAdmDbTableGrid.EditIndex) == e.Item.DataItemIndex)
			{
			}
			else
			{
			}
			// *** GridItemDataBound (after) Web Rule End *** //
		}

		protected void cColumnId5hl_Click(object sender, System.EventArgs e)
		{
			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != "0") { Session.Remove(KEY_lastSortUrl); }
			Session[KEY_lastSortTog] = "Y"; Session[KEY_lastSortCol] = "0"; Session[KEY_lastSortExp] = "ColumnId5";Session[KEY_lastSortImg] = "cColumnId5hi";
			cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs("ColumnId5", SortDirection.Ascending));
		}

		protected void cColumnIndex5hl_Click(object sender, System.EventArgs e)
		{
			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != "1") { Session.Remove(KEY_lastSortUrl); }
			Session[KEY_lastSortTog] = "Y"; Session[KEY_lastSortCol] = "1"; Session[KEY_lastSortExp] = "ColumnIndex5";Session[KEY_lastSortImg] = "cColumnIndex5hi";
			cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs("ColumnIndex5", SortDirection.Ascending));
		}

		protected void cExternalTable5hl_Click(object sender, System.EventArgs e)
		{
			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != "2") { Session.Remove(KEY_lastSortUrl); }
			Session[KEY_lastSortTog] = "Y"; Session[KEY_lastSortCol] = "2"; Session[KEY_lastSortExp] = "ExternalTable5";Session[KEY_lastSortImg] = "cExternalTable5hi";
			cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs("ExternalTable5", SortDirection.Ascending));
		}

		protected void cColumnName5hl_Click(object sender, System.EventArgs e)
		{
			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != "3") { Session.Remove(KEY_lastSortUrl); }
			Session[KEY_lastSortTog] = "Y"; Session[KEY_lastSortCol] = "3"; Session[KEY_lastSortExp] = "ColumnName5";Session[KEY_lastSortImg] = "cColumnName5hi";
			cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs("ColumnName5", SortDirection.Ascending));
		}

		protected void cDataType5hl_Click(object sender, System.EventArgs e)
		{
			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != "4") { Session.Remove(KEY_lastSortUrl); }
			Session[KEY_lastSortTog] = "Y"; Session[KEY_lastSortCol] = "4"; Session[KEY_lastSortExp] = "DataType5Text";Session[KEY_lastSortImg] = "cDataType5hi";
			cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs("DataType5Text", SortDirection.Ascending));
		}

		protected void cColumnLength5hl_Click(object sender, System.EventArgs e)
		{
			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != "5") { Session.Remove(KEY_lastSortUrl); }
			Session[KEY_lastSortTog] = "Y"; Session[KEY_lastSortCol] = "5"; Session[KEY_lastSortExp] = "ColumnLength5";Session[KEY_lastSortImg] = "cColumnLength5hi";
			cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs("ColumnLength5", SortDirection.Ascending));
		}

		protected void cColumnScale5hl_Click(object sender, System.EventArgs e)
		{
			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != "6") { Session.Remove(KEY_lastSortUrl); }
			Session[KEY_lastSortTog] = "Y"; Session[KEY_lastSortCol] = "6"; Session[KEY_lastSortExp] = "ColumnScale5";Session[KEY_lastSortImg] = "cColumnScale5hi";
			cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs("ColumnScale5", SortDirection.Ascending));
		}

		protected void cDefaultValue5hl_Click(object sender, System.EventArgs e)
		{
			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != "7") { Session.Remove(KEY_lastSortUrl); }
			Session[KEY_lastSortTog] = "Y"; Session[KEY_lastSortCol] = "7"; Session[KEY_lastSortExp] = "DefaultValue5";Session[KEY_lastSortImg] = "cDefaultValue5hi";
			cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs("DefaultValue5", SortDirection.Ascending));
		}

		protected void cAllowNulls5hl_Click(object sender, System.EventArgs e)
		{
			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != "8") { Session.Remove(KEY_lastSortUrl); }
			Session[KEY_lastSortTog] = "Y"; Session[KEY_lastSortCol] = "8"; Session[KEY_lastSortExp] = "AllowNulls5";Session[KEY_lastSortImg] = "cAllowNulls5hi";
			cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs("AllowNulls5", SortDirection.Ascending));
		}

		protected void cAllowNulls5hc_CheckedChanged(object sender, System.EventArgs e)
		{
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			if (dt != null && (cAdmDbTableGrid.EditIndex < 0 || UpdateGridRow(sender, new CommandEventArgs("Save", ""))))
			{
				CheckBox cc = (CheckBox)sender;
				bAllowNulls5 = cc.Checked;
				foreach (DataRowView drv in dt.DefaultView)
				{
					if (cc.Checked) {drv["AllowNulls5"] = "Y";} else {drv["AllowNulls5"] = "N";}
				}
				Session[KEY_dtAdmDbTableGrid] = dt;
				cAdmDbTableGrid_DataBind(dt.DefaultView);
			}
		}

		protected void cColumnIdentity5hl_Click(object sender, System.EventArgs e)
		{
			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != "9") { Session.Remove(KEY_lastSortUrl); }
			Session[KEY_lastSortTog] = "Y"; Session[KEY_lastSortCol] = "9"; Session[KEY_lastSortExp] = "ColumnIdentity5";Session[KEY_lastSortImg] = "cColumnIdentity5hi";
			cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs("ColumnIdentity5", SortDirection.Ascending));
		}

		protected void cPrimaryKey5hl_Click(object sender, System.EventArgs e)
		{
			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != "10") { Session.Remove(KEY_lastSortUrl); }
			Session[KEY_lastSortTog] = "Y"; Session[KEY_lastSortCol] = "10"; Session[KEY_lastSortExp] = "PrimaryKey5";Session[KEY_lastSortImg] = "cPrimaryKey5hi";
			cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs("PrimaryKey5", SortDirection.Ascending));
		}

		protected void cIsIndexU5hl_Click(object sender, System.EventArgs e)
		{
			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != "11") { Session.Remove(KEY_lastSortUrl); }
			Session[KEY_lastSortTog] = "Y"; Session[KEY_lastSortCol] = "11"; Session[KEY_lastSortExp] = "IsIndexU5";Session[KEY_lastSortImg] = "cIsIndexU5hi";
			cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs("IsIndexU5", SortDirection.Ascending));
		}

		protected void cIsIndex5hl_Click(object sender, System.EventArgs e)
		{
			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != "12") { Session.Remove(KEY_lastSortUrl); }
			Session[KEY_lastSortTog] = "Y"; Session[KEY_lastSortCol] = "12"; Session[KEY_lastSortExp] = "IsIndex5";Session[KEY_lastSortImg] = "cIsIndex5hi";
			cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs("IsIndex5", SortDirection.Ascending));
		}

		protected void cColObjective5hl_Click(object sender, System.EventArgs e)
		{
			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != "13") { Session.Remove(KEY_lastSortUrl); }
			Session[KEY_lastSortTog] = "Y"; Session[KEY_lastSortCol] = "13"; Session[KEY_lastSortExp] = "ColObjective5";Session[KEY_lastSortImg] = "cColObjective5hi";
			cAdmDbTableGrid_OnSorting(sender, new ListViewSortEventArgs("ColObjective5", SortDirection.Ascending));
		}

		private double AggrGrid(DataView dv, string ColName, string AggrInst)
		{
			int dvCnt = dv.Count;
			bool bFirst = true;
			if (AggrInst == "C") {return dvCnt;}
			else try
			{
				double tt = 0;
				double vv = 0;
				double mm = 0;
				double ii = 0;
				foreach (DataRowView drv in dv)
				{
					if (drv[ColName].ToString() != string.Empty)
				    {
				        vv = Double.Parse(drv[ColName].ToString());
				        if (bFirst) { mm = vv; ii = vv; bFirst = false; }
				        else
				        {
				            if (vv > mm) { mm = vv; }
				            if (vv < ii) { ii = vv; }
				        }
				        tt = tt + vv;
				    }
				}
				if (AggrInst == "S") {return tt;}
				else if (AggrInst == "M") { return mm; }
				else if (AggrInst == "I") { return ii; }
				else if (AggrInst == "A" && dvCnt > 0) {return tt/dvCnt;} else {return 0;}
			} catch { return 0; }
		}
		protected string GetAggr(string columnName, string typ)
		{
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			if (dt != null) return AggrGrid(dt.DefaultView, columnName, typ).ToString("F9"); //to prevent scientific notation
			else return string.Empty;
		}

		protected void cAdmDbTableGrid_OnItemEditing(object sender, ListViewEditEventArgs e)
		{
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			if ((ValidPage()) && UpdateGridRow(sender, new CommandEventArgs("Save", "")) && dt != null && dt.DefaultView.Count > GetDataItemIndex(e.NewEditIndex))
			{
				cAdmDbTableGrid.EditIndex = e.NewEditIndex;
				cAdmDbTableGrid_DataBind(null);
				cDataType5Search_Script();
				cDataType5_SelectedIndexChanged((object)cAdmDbTableGrid.EditItem.FindControl("cDataType5"), new EventArgs());
				Control wc = null;
				string idx = Page.Request["__EVENTARGUMENT"];
				if (!string.IsNullOrEmpty(idx))
				{
				    Control ctrlToFocus = cAdmDbTableGrid.EditItem.FindControl("c" + idx);
				    if (((WebControl)ctrlToFocus).Enabled) { wc = ctrlToFocus; }
				}
				if (wc == null) { wc = FindEditableControl(cAdmDbTableGrid.EditItem); }
				if (wc != null)
             {
                 if (wc is RoboCoder.WebControls.ComboBox)
                 {
                     if (isMobile.Text != "isMobile") ScriptManager.GetCurrent(Parent.Page).SetFocus(((RoboCoder.WebControls.ComboBox)wc).FocusID);
                 }
                 else if (wc is CheckBox && ("c" + idx) == wc.ID)
                 {
                     ((CheckBox)wc).Checked = !((CheckBox)wc).Checked; ShowDirty(true);
                 }
                 else
                 {
                     if (isMobile.Text != "isMobile") ScriptManager.GetCurrent(Parent.Page).SetFocus(wc.ClientID);
                 }
             }
             MkMobileLabel(cAdmDbTableGrid.EditItem);
		    }
		    else { e.Cancel = true; }
		}

		private void MkMobileLabel(ListViewItem lvi)
		{
		    Label ml = null;
		    ml = lvi.FindControl("cColumnId5ml") as Label;
		    if (ml != null) { ml.Text = ColumnHeaderText(19); }
		    ml = lvi.FindControl("cColumnIndex5ml") as Label;
		    if (ml != null) { ml.Text = ColumnHeaderText(20); }
		    ml = lvi.FindControl("cExternalTable5ml") as Label;
		    if (ml != null) { ml.Text = ColumnHeaderText(21); }
		    ml = lvi.FindControl("cColumnName5ml") as Label;
		    if (ml != null) { ml.Text = ColumnHeaderText(22); }
		    ml = lvi.FindControl("cDataType5ml") as Label;
		    if (ml != null) { ml.Text = ColumnHeaderText(23); }
		    ml = lvi.FindControl("cColumnLength5ml") as Label;
		    if (ml != null) { ml.Text = ColumnHeaderText(24); }
		    ml = lvi.FindControl("cColumnScale5ml") as Label;
		    if (ml != null) { ml.Text = ColumnHeaderText(25); }
		    ml = lvi.FindControl("cDefaultValue5ml") as Label;
		    if (ml != null) { ml.Text = ColumnHeaderText(26); }
		    ml = lvi.FindControl("cAllowNulls5ml") as Label;
		    if (ml != null) { ml.Text = ColumnHeaderText(27); }
		    ml = lvi.FindControl("cColumnIdentity5ml") as Label;
		    if (ml != null) { ml.Text = ColumnHeaderText(28); }
		    ml = lvi.FindControl("cPrimaryKey5ml") as Label;
		    if (ml != null) { ml.Text = ColumnHeaderText(29); }
		    ml = lvi.FindControl("cIsIndexU5ml") as Label;
		    if (ml != null) { ml.Text = ColumnHeaderText(30); }
		    ml = lvi.FindControl("cIsIndex5ml") as Label;
		    if (ml != null) { ml.Text = ColumnHeaderText(31); }
		    ml = lvi.FindControl("cColObjective5ml") as Label;
		    if (ml != null) { ml.Text = ColumnHeaderText(32); }
		}

		protected void GridFill(ListViewItem lvi, DataTable dt, DataRow dr, bool bInsert)
		{
			TextBox tb = null;
			tb = (TextBox)lvi.FindControl("cColumnIndex5");
			if (tb != null)
			{
				if (tb.Text != string.Empty) {dr["ColumnIndex5"] = tb.Text;} else {dr["ColumnIndex5"] = System.DBNull.Value;}
			}
			tb = (TextBox)lvi.FindControl("cExternalTable5");
			if (tb != null)
			{
				if (tb.Text != string.Empty) {dr["ExternalTable5"] = tb.Text;} else {dr["ExternalTable5"] = System.DBNull.Value;}
			}
			tb = (TextBox)lvi.FindControl("cColumnName5");
			if (tb != null)
			{
				if (tb.Text != string.Empty) {dr["ColumnName5"] = tb.Text;} else {dr["ColumnName5"] = System.DBNull.Value;}
			}
			DropDownList ddl = null;
			ddl = (DropDownList)lvi.FindControl("cDataType5");
			if (ddl != null)
			{
				if (ddl.SelectedIndex >= 0 && ddl.SelectedValue.ToString() != string.Empty)
				{
					dr["DataType5"] = ddl.SelectedValue;
					dr["DataType5Text"] = ddl.SelectedItem.Text;
				}
				else
				{
					dr["DataType5"] = System.DBNull.Value;
					dr["DataType5Text"] = System.DBNull.Value;
				}
			}
			tb = (TextBox)lvi.FindControl("cColumnLength5");
			if (tb != null)
			{
				if (tb.Text != string.Empty) {dr["ColumnLength5"] = tb.Text;} else {dr["ColumnLength5"] = System.DBNull.Value;}
			}
			tb = (TextBox)lvi.FindControl("cColumnScale5");
			if (tb != null)
			{
				if (tb.Text != string.Empty) {dr["ColumnScale5"] = tb.Text;} else {dr["ColumnScale5"] = System.DBNull.Value;}
			}
			tb = (TextBox)lvi.FindControl("cDefaultValue5");
			if (tb != null)
			{
				if (tb.Text != string.Empty) {dr["DefaultValue5"] = tb.Text;} else {dr["DefaultValue5"] = System.DBNull.Value;}
			}
			CheckBox cb = null;
			cb = (CheckBox)lvi.FindControl("cAllowNulls5");
			if (cb != null)
			{
				dr["AllowNulls5"] = base.SetBool(cb.Checked);
			}
			cb = (CheckBox)lvi.FindControl("cColumnIdentity5");
			if (cb != null)
			{
				dr["ColumnIdentity5"] = base.SetBool(cb.Checked);
			}
			cb = (CheckBox)lvi.FindControl("cPrimaryKey5");
			if (cb != null)
			{
				dr["PrimaryKey5"] = base.SetBool(cb.Checked);
			}
			cb = (CheckBox)lvi.FindControl("cIsIndexU5");
			if (cb != null)
			{
				dr["IsIndexU5"] = base.SetBool(cb.Checked);
			}
			cb = (CheckBox)lvi.FindControl("cIsIndex5");
			if (cb != null)
			{
				dr["IsIndex5"] = base.SetBool(cb.Checked);
			}
			tb = (TextBox)lvi.FindControl("cColObjective5");
			if (tb != null)
			{
				if (tb.Text != string.Empty) {dr["ColObjective5"] = tb.Text;} else {dr["ColObjective5"] = System.DBNull.Value;}
			}
		    if (bInsert) { dt.Rows.InsertAt(dr, 0); }
			Session[KEY_dtAdmDbTableGrid] = dt;
			cAdmDbTableGrid.EditIndex = -1;
			cAdmDbTableGrid_DataBind(dt.DefaultView);
		}

		protected void cAdmDbTableGrid_OnItemUpdating(object sender, ListViewUpdateEventArgs e)
		{
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			if (dt != null && dt.Rows.Count > 0)
			{
				DataRow dr = dt.DefaultView[GetDataItemIndex(e.ItemIndex)].Row;
			    GridFill(cAdmDbTableGrid.EditItem, dt, dr, false);
			    dr["_NewRow"] = "N";
			    if (dt.Columns.Contains("_SortOrder")) dr["_SortOrder"] = null;
			}
		}

		protected void cAdmDbTableGrid_OnItemCanceling(object sender, ListViewCancelEventArgs e)
		{
			PanelTop.Update();
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			DataView dv = dt != null ? dt.DefaultView : null;
			if (dv != null && dv[GetDataItemIndex(e.ItemIndex)]["_NewRow"].ToString() == "Y")
			{
				cAdmDbTableGrid_OnItemDeleting(sender, new ListViewDeleteEventArgs(e.ItemIndex));
			}
			if (dt.Columns.Contains("_SortOrder")) dt.DefaultView[GetDataItemIndex(e.ItemIndex)].Row["_SortOrder"] = null;
			cAdmDbTableGrid.EditIndex = -1; cAdmDbTableGrid_DataBind(null);
		}

		protected void cDeleteAllButton_Click(object sender, System.EventArgs e)
		{
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			DataView dv = dt != null ? dt.DefaultView : null;
			if (dv != null && (cAdmDbTableGrid.EditIndex < 0 || UpdateGridRow(sender, new CommandEventArgs("Save", ""))))
			{
				GotoPage(0);
				while (dv.Count > 0) {dv.Delete(0);}
				Session[KEY_dtAdmDbTableGrid] = dt;
				cAdmDbTableGrid.EditIndex = -1; cAdmDbTableGrid_DataBind(dv);
			}
		}

		protected void cAdmDbTableGrid_OnItemDeleting(object sender, ListViewDeleteEventArgs e)
		{
			DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
			DataView dv = dt != null ? dt.DefaultView : null;
			DataRow dr = dv != null ? dv[GetDataItemIndex(e.ItemIndex)].Row : null;
			if (dv != null && (cAdmDbTableGrid.EditIndex == e.ItemIndex || UpdateGridRow(sender, new CommandEventArgs("Save",""))))
			{
				// *** Delete Grid Row (before) Web Rule End *** //
				dr.Delete();
				Session[KEY_dtAdmDbTableGrid] = dt;
				cAdmDbTableGrid.EditIndex = -1; cAdmDbTableGrid_DataBind(dv);
			}
		}

		public void cNewSaveButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (Before) Web Rule starts here *** //
			try {
			    string msg = SaveDb(sender, new EventArgs());
			    cNewButton_Click(sender, new EventArgs());
			    if (msg != string.Empty && Config.PromptMsg) { bInfoNow.Value = "Y"; PreMsgPopup(msg); }
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
			// *** System Button Click (After) Web Rule starts here *** //
		}

		public void cNewButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (Before) Web Rule starts here *** //
			cAdmDbTable2List.ClearSearch(); Session.Remove(KEY_dtAdmDbTable2List);
			PopAdmDbTable2List(sender, e, false, null);
			// *** System Button Click (After) Web Rule starts here *** //
		}

		public void cClearButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (Before) Web Rule starts here *** //
			ClearMaster(sender, e);
			cDeleteAllButton_Click(sender, new EventArgs());
			// *** System Button Click (After) Web Rule starts here *** //
		}

		public void cCopyButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (Before) Web Rule starts here *** //
			cTableId3.Text = string.Empty;
			cAdmDbTable2List.ClearSearch(); Session.Remove(KEY_dtAdmDbTable2List);
			ShowDirty(true);
			// *** System Button Click (After) Web Rule starts here *** //
		}

		public void cCopySaveButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (Before) Web Rule starts here *** //
			try {
			    string msg = SaveDb(sender, new EventArgs());
			    cCopyButton_Click(sender, new EventArgs());
			    if (msg != string.Empty && Config.PromptMsg) { bInfoNow.Value = "Y"; PreMsgPopup(msg); }
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
			// *** System Button Click (After) Web Rule starts here *** //
		}

		public void cUndoAllButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (Before) Web Rule starts here *** //
			if (cTableId3.Text == string.Empty) { cClearButton_Click(sender, new EventArgs()); ShowDirty(false); PanelTop.Update();}
			else { PopAdmDbTable2List(sender, e, false, cTableId3.Text); }
			// *** System Button Click (After) Web Rule starts here *** //
		}

		public void cPreviewButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (Before) Web Rule starts here *** //
			// *** System Button Click (After) Web Rule starts here *** //
		}

		public void cEditButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (Before) Web Rule starts here *** //
			cScreenSearch.Visible = true;
			cSystem.Visible = true;
			bUseCri.Value = "Y"; GetCriteria(GetScrCriteria());
			Session.Remove(KEY_dtAdmDbTable2List); PopAdmDbTable2List(sender, e, false, null);
			cEditButton.Visible = false;
			// *** System Button Click (After) Web Rule starts here *** //
		}

		public void cSaveCloseButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (Before) Web Rule starts here *** //
			try {
			    string msg = SaveDb(sender, new EventArgs());
			    if (msg != string.Empty)
			    {
			        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "closeDlg", @"<script type='text/javascript'>window.parent.closeParentDlg();</script>", false);
			    }
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
			// *** System Button Click (After) Web Rule starts here *** //
		}

		private string SaveDb(object sender, System.EventArgs e)
		{
			string rtn = string.Empty;
			bool noTrans = Config.NoTrans;
			int commandTimeOut = Config.CommandTimeOut;
			// *** System Button Click (Before) Web Rule starts here *** //
			string pid = string.Empty;
			if (ValidPage() && (cAdmDbTableGrid.EditIndex < 0 || UpdateGridRow(cAdmDbTableGrid, new CommandEventArgs("Save", ""))))
			{
				DataTable dt = (DataTable)Session[KEY_dtAdmDbTableGrid];
				DataView dv = dt != null ? dt.DefaultView : null;
				string ftr = string.Empty;
				if (dv.RowFilter != string.Empty) { ftr = dv.RowFilter; dv.RowFilter = string.Empty; }
				AdmDbTable2 ds = PrepAdmDbTableData(dv,cTableId3.Text == string.Empty);
				if (ftr != string.Empty) {dv.RowFilter = ftr;}
				if (!string.IsNullOrEmpty(cAdmDbTable2List.SelectedValue) && cTableId3.Text != cAdmDbTable2List.SelectedValue)
				{
					PreMsgPopup("Primary key cannot be changed");
					return rtn;
				}
				if (string.IsNullOrEmpty(cAdmDbTable2List.SelectedValue))	// Add
				{
					if (ds != null)
					{
						pid = (new AdminSystem()).AddData(2,false,base.LUser,base.LImpr,base.LCurr,ds,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),base.CPrj,base.CSrc,noTrans,commandTimeOut);
					}
					if (!string.IsNullOrEmpty(pid))
					{
						cAdmDbTable2List.ClearSearch(); Session.Remove(KEY_dtAdmDbTable2List);
						ShowDirty(false); bUseCri.Value = "Y"; PopAdmDbTable2List(sender, e, false, pid);
						rtn = GetScreenHlp().Rows[0]["AddMsg"].ToString();
					}
				}
				else {
					bool bValid7 = false;
					if (ds != null && (new AdminSystem()).UpdData(2,false,base.LUser,base.LImpr,base.LCurr,ds,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),base.CPrj,base.CSrc,noTrans,commandTimeOut)) {bValid7 = true;}
					if (bValid7)
					{
						cAdmDbTable2List.ClearSearch(); Session.Remove(KEY_dtAdmDbTable2List);
						Session[KEY_currPageIndex] = GetCurrPageIndex();
						ShowDirty(false); PopAdmDbTable2List(sender, e, false, ds.Tables["AdmDbTable"].Rows[0]["TableId3"]);
						rtn = GetScreenHlp().Rows[0]["UpdMsg"].ToString();
					}
				}
			}
			// *** System Button Click (After) Web Rule starts here *** //
			return rtn;
		}

		public void cSaveButton_Click(object sender, System.EventArgs e)
		{
			try {
			    string msg = SaveDb(sender, e);
			    if (msg != string.Empty && Config.PromptMsg) { bInfoNow.Value = "Y"; PreMsgPopup(msg); }
			}
			catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
		}

		public void cDeleteButton_Click(object sender, System.EventArgs e)
		{
			// *** System Button Click (Before) Web Rule starts here *** //
			if (cTableId3.Text != string.Empty)
			{
				AdmDbTable2 ds = PrepAdmDbTableData(null,false);
				try
				{
					if (ds != null && (new AdminSystem()).DelData(2,false,base.LUser,base.LImpr,base.LCurr,ds,(string)Session[KEY_sysConnectionString],base.AppPwd(base.LCurr.DbId),base.CPrj,base.CSrc))
					{
						cAdmDbTable2List.ClearSearch(); Session.Remove(KEY_dtAdmDbTable2List);
						ShowDirty(false); PopAdmDbTable2List(sender, e, false, null);
						if (Config.PromptMsg) {bInfoNow.Value = "Y"; PreMsgPopup(GetScreenHlp().Rows[0]["DelMsg"].ToString());}
					}
				}
				catch (Exception err) { bErrNow.Value = "Y"; PreMsgPopup(err.Message); return; }
			}
			// *** System Button Click (After) Web Rule starts here *** //
		}

		private AdmDbTable2 PrepAdmDbTableData(DataView dv, bool bAdd)
		{
			AdmDbTable2 ds = new AdmDbTable2();
			DataRow dr = ds.Tables["AdmDbTable"].NewRow();
			DataRow drType = ds.Tables["AdmDbTable"].NewRow();
			DataRow drDisp = ds.Tables["AdmDbTable"].NewRow();
			if (bAdd) { dr["TableId3"] = string.Empty; } else { dr["TableId3"] = cTableId3.Text; }
			drType["TableId3"] = "Numeric"; drDisp["TableId3"] = "TextBox";
			try {dr["SystemId3"] = cSystemId3.SelectedValue;} catch {}
			drType["SystemId3"] = "Numeric"; drDisp["SystemId3"] = "DropDownList";
			try {dr["TableName3"] = cTableName3.Text.Trim();} catch {}
			drType["TableName3"] = "VarChar"; drDisp["TableName3"] = "TextBox";
			try {dr["TableDesc3"] = cTableDesc3.Text.Trim();} catch {}
			drType["TableDesc3"] = "VarWChar"; drDisp["TableDesc3"] = "TextBox";
			try {dr["TblObjective3"] = cTblObjective3.Text;} catch {}
			drType["TblObjective3"] = "VarWChar"; drDisp["TblObjective3"] = "MultiLine";
			try {dr["VirtualTbl3"] = base.SetBool(cVirtualTbl3.Checked);} catch {}
			drType["VirtualTbl3"] = "Char"; drDisp["VirtualTbl3"] = "CheckBox";
			try {dr["MultiDesignDb3"] = base.SetBool(cMultiDesignDb3.Checked);} catch {}
			drType["MultiDesignDb3"] = "Char"; drDisp["MultiDesignDb3"] = "CheckBox";
			try {dr["UploadSheet"] = cUploadSheet.Text;} catch {}
			drType["UploadSheet"] = string.Empty; drDisp["UploadSheet"] = "Upload";
			try {dr["SheetNameList"] = cSheetNameList.SelectedValue;} catch {}
			drType["SheetNameList"] = string.Empty; drDisp["SheetNameList"] = "DropDownList";
			try {dr["RowsToExamine"] = cRowsToExamine.Text.Trim();} catch {}
			drType["RowsToExamine"] = string.Empty; drDisp["RowsToExamine"] = "TextBox";
			try {dr["ModifiedBy3"] = base.LUser.UsrId.ToString();} catch {};
			drType["ModifiedBy3"] = "Numeric"; drDisp["ModifiedBy3"] = "DropDownList";
			try {dr["LastSyncDt3"] = base.ToIntDateTime(cLastSyncDt3.Text,true,true);} catch {}
			drType["LastSyncDt3"] = "DBTimeStamp"; drDisp["LastSyncDt3"] = "ShortDateTimeUTC";
			try {dr["VirtualSql3"] = cVirtualSql3.Text;} catch {}
			drType["VirtualSql3"] = "VarWChar"; drDisp["VirtualSql3"] = "MultiLine";
			if (dv != null)
			{
				ds.Tables["AdmDbTableDef"].Rows.Add(MakeTypRow(ds.Tables["AdmDbTableDef"].NewRow()));
				ds.Tables["AdmDbTableDef"].Rows.Add(MakeDisRow(ds.Tables["AdmDbTableDef"].NewRow()));
				if (bAdd)
				{
					foreach (DataRowView drv in dv)
					{
						ds.Tables["AdmDbTableAdd"].Rows.Add(MakeColRow(ds.Tables["AdmDbTableAdd"].NewRow(), drv, true));
					}
				}
				else
				{
					dv.RowStateFilter = DataViewRowState.ModifiedCurrent;
					foreach (DataRowView drv in dv)
					{
						ds.Tables["AdmDbTableUpd"].Rows.Add(MakeColRow(ds.Tables["AdmDbTableUpd"].NewRow(), drv, false));
					}
					dv.RowStateFilter = DataViewRowState.Added;
					foreach (DataRowView drv in dv)
					{
						ds.Tables["AdmDbTableAdd"].Rows.Add(MakeColRow(ds.Tables["AdmDbTableAdd"].NewRow(), drv, true));
					}
					dv.RowStateFilter = DataViewRowState.Deleted;
					foreach (DataRowView drv in dv)
					{
						ds.Tables["AdmDbTableDel"].Rows.Add(MakeColRow(ds.Tables["AdmDbTableDel"].NewRow(), drv, false));
					}
					dv.RowStateFilter = DataViewRowState.CurrentRows;
				}
			}
			ds.Tables["AdmDbTable"].Rows.Add(dr); ds.Tables["AdmDbTable"].Rows.Add(drType); ds.Tables["AdmDbTable"].Rows.Add(drDisp);
			return ds;
		}

		public bool CanAct(char typ) { return CanAct(typ, GetAuthRow(), cAdmDbTable2List.SelectedValue.ToString()); }

		private bool ValidPage()
		{
			EnableValidators(true);
			Page.Validate();
			if (!Page.IsValid) { PanelTop.Update(); return false; }
			DataTable dt = null;
			dt = (DataTable)Session[KEY_dtSystemId3];
			if (dt != null && dt.Rows.Count <= 0)
			{
				bErrNow.Value = "Y"; PreMsgPopup("Value is expected for 'SystemId', please investigate."); return false;
			}
			dt = (DataTable)Session[KEY_dtDataType5];
			if (dt != null && dt.Rows.Count <= 0)
			{
				bErrNow.Value = "Y"; PreMsgPopup("Value is expected for 'DataType', please investigate."); return false;
			}
			return true;
		}

		private DataRow MakeTypRow(DataRow dr)
		{
			dr["TableId3"] = System.Data.OleDb.OleDbType.Numeric.ToString();
			dr["ColumnId5"] = System.Data.OleDb.OleDbType.Numeric.ToString();
			dr["ColumnIndex5"] = System.Data.OleDb.OleDbType.Numeric.ToString();
			dr["ExternalTable5"] = System.Data.OleDb.OleDbType.VarChar.ToString();
			dr["ColumnName5"] = System.Data.OleDb.OleDbType.VarChar.ToString();
			dr["DataType5"] = System.Data.OleDb.OleDbType.Numeric.ToString();
			dr["ColumnLength5"] = System.Data.OleDb.OleDbType.Numeric.ToString();
			dr["ColumnScale5"] = System.Data.OleDb.OleDbType.Numeric.ToString();
			dr["DefaultValue5"] = System.Data.OleDb.OleDbType.VarWChar.ToString();
			dr["AllowNulls5"] = System.Data.OleDb.OleDbType.Char.ToString();
			dr["ColumnIdentity5"] = System.Data.OleDb.OleDbType.Char.ToString();
			dr["PrimaryKey5"] = System.Data.OleDb.OleDbType.Char.ToString();
			dr["IsIndexU5"] = System.Data.OleDb.OleDbType.Char.ToString();
			dr["IsIndex5"] = System.Data.OleDb.OleDbType.Char.ToString();
			dr["ColObjective5"] = System.Data.OleDb.OleDbType.VarWChar.ToString();
			return dr;
		}

		private DataRow MakeDisRow(DataRow dr)
		{
			dr["TableId3"] = "TextBox";
			dr["ColumnId5"] = "TextBox";
			dr["ColumnIndex5"] = "TextBox";
			dr["ExternalTable5"] = "TextBox";
			dr["ColumnName5"] = "TextBox";
			dr["DataType5"] = "DropDownList";
			dr["ColumnLength5"] = "TextBox";
			dr["ColumnScale5"] = "TextBox";
			dr["DefaultValue5"] = "TextBox";
			dr["AllowNulls5"] = "CheckBoxAll";
			dr["ColumnIdentity5"] = "CheckBox";
			dr["PrimaryKey5"] = "CheckBox";
			dr["IsIndexU5"] = "CheckBox";
			dr["IsIndex5"] = "CheckBox";
			dr["ColObjective5"] = "TextBox";
			return dr;
		}

		private DataRow MakeColRow(DataRow dr, DataRowView drv, bool bAdd)
		{
			dr["TableId3"] = cTableId3.Text;
			DataTable dtAuth = GetAuthCol();
			if (dtAuth != null)
			{
				dr["ColumnId5"] = drv["ColumnId5"].ToString().Trim();
				dr["ColumnIndex5"] = drv["ColumnIndex5"].ToString().Trim();
				if (bAdd && dtAuth.Rows[20]["ColReadOnly"].ToString() == "Y" && dr["ColumnIndex5"].ToString() == string.Empty) {dr["ColumnIndex5"] = System.DBNull.Value;}
				dr["ExternalTable5"] = drv["ExternalTable5"].ToString().Trim();
				if (bAdd && dtAuth.Rows[21]["ColReadOnly"].ToString() == "Y" && dr["ExternalTable5"].ToString() == string.Empty) {dr["ExternalTable5"] = System.DBNull.Value;}
				dr["ColumnName5"] = drv["ColumnName5"].ToString().Trim();
				dr["DataType5"] = drv["DataType5"];
				dr["ColumnLength5"] = drv["ColumnLength5"].ToString().Trim();
				dr["ColumnScale5"] = drv["ColumnScale5"].ToString().Trim();
				if (bAdd && dtAuth.Rows[25]["ColReadOnly"].ToString() == "Y" && dr["ColumnScale5"].ToString() == string.Empty) {dr["ColumnScale5"] = System.DBNull.Value;}
				dr["DefaultValue5"] = drv["DefaultValue5"].ToString().Trim();
				if (bAdd && dtAuth.Rows[26]["ColReadOnly"].ToString() == "Y" && dr["DefaultValue5"].ToString() == string.Empty) {dr["DefaultValue5"] = System.DBNull.Value;}
				dr["AllowNulls5"] = drv["AllowNulls5"];
				dr["ColumnIdentity5"] = drv["ColumnIdentity5"];
				dr["PrimaryKey5"] = drv["PrimaryKey5"];
				dr["IsIndexU5"] = drv["IsIndexU5"];
				dr["IsIndex5"] = drv["IsIndex5"];
				dr["ColObjective5"] = drv["ColObjective5"].ToString().Trim();
				if (bAdd && dtAuth.Rows[32]["ColReadOnly"].ToString() == "Y" && dr["ColObjective5"].ToString() == string.Empty) {dr["ColObjective5"] = System.DBNull.Value;}
			}
			return dr;
		}

		private bool UpdateGridRow(object sender, CommandEventArgs e)
		{
			if (cAdmDbTableGrid.EditIndex > -1)
			{
				cAdmDbTableGrid_OnItemUpdating(sender, new ListViewUpdateEventArgs(cAdmDbTableGrid.EditIndex));
			}
			return true;
		}

		protected void cAdmDbTableGrid_OnPreRender(object sender, System.EventArgs e)
		{
			System.Web.UI.WebControls.Image hi = null;
			hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl("cColumnId5hi"); if (hi != null) { hi.Visible = false; }
			hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl("cColumnIndex5hi"); if (hi != null) { hi.Visible = false; }
			hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl("cExternalTable5hi"); if (hi != null) { hi.Visible = false; }
			hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl("cColumnName5hi"); if (hi != null) { hi.Visible = false; }
			hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl("cDataType5hi"); if (hi != null) { hi.Visible = false; }
			hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl("cColumnLength5hi"); if (hi != null) { hi.Visible = false; }
			hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl("cColumnScale5hi"); if (hi != null) { hi.Visible = false; }
			hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl("cDefaultValue5hi"); if (hi != null) { hi.Visible = false; }
			hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl("cAllowNulls5hi"); if (hi != null) { hi.Visible = false; }
			hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl("cColumnIdentity5hi"); if (hi != null) { hi.Visible = false; }
			hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl("cPrimaryKey5hi"); if (hi != null) { hi.Visible = false; }
			hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl("cIsIndexU5hi"); if (hi != null) { hi.Visible = false; }
			hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl("cIsIndex5hi"); if (hi != null) { hi.Visible = false; }
			hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl("cColObjective5hi"); if (hi != null) { hi.Visible = false; }
			if (Session[KEY_lastSortImg] != null)
			{
				hi = (System.Web.UI.WebControls.Image)cAdmDbTableGrid.FindControl((string)Session[KEY_lastSortImg]);
				if (hi != null) { hi.ImageUrl = Utils.AddTilde((string)Session[KEY_lastSortUrl]); hi.Visible = true; }
			}
			IgnoreHeaderConfirm((LinkButton)cAdmDbTableGrid.FindControl("cColumnId5hl"));
			IgnoreHeaderConfirm((LinkButton)cAdmDbTableGrid.FindControl("cColumnIndex5hl"));
			IgnoreHeaderConfirm((LinkButton)cAdmDbTableGrid.FindControl("cExternalTable5hl"));
			IgnoreHeaderConfirm((LinkButton)cAdmDbTableGrid.FindControl("cColumnName5hl"));
			IgnoreHeaderConfirm((LinkButton)cAdmDbTableGrid.FindControl("cDataType5hl"));
			IgnoreHeaderConfirm((LinkButton)cAdmDbTableGrid.FindControl("cColumnLength5hl"));
			IgnoreHeaderConfirm((LinkButton)cAdmDbTableGrid.FindControl("cColumnScale5hl"));
			IgnoreHeaderConfirm((LinkButton)cAdmDbTableGrid.FindControl("cDefaultValue5hl"));
			IgnoreHeaderConfirm((LinkButton)cAdmDbTableGrid.FindControl("cAllowNulls5hl"));
			IgnoreHeaderConfirm((LinkButton)cAdmDbTableGrid.FindControl("cColumnIdentity5hl"));
			IgnoreHeaderConfirm((LinkButton)cAdmDbTableGrid.FindControl("cPrimaryKey5hl"));
			IgnoreHeaderConfirm((LinkButton)cAdmDbTableGrid.FindControl("cIsIndexU5hl"));
			IgnoreHeaderConfirm((LinkButton)cAdmDbTableGrid.FindControl("cIsIndex5hl"));
			IgnoreHeaderConfirm((LinkButton)cAdmDbTableGrid.FindControl("cColObjective5hl"));

			// Take care of CheckBoxAll:
			DataTable dtAuth = GetAuthCol();
			DataView dvAdmDbTableGrid = ((DataTable)Session[KEY_dtAdmDbTableGrid]).DefaultView;
			CheckBox cba = null;
			cba = (CheckBox)cAdmDbTableGrid.FindControl("cAllowNulls5hc");
			if (cba != null)
			{
				if (dtAuth != null && dtAuth.Rows[27]["ColReadOnly"].ToString() == "Y") {cba.Enabled = false;}
				else
				{
					int yy = 0;
					int nn = 0;
					int zz = 0;
					foreach (DataRowView drv in dvAdmDbTableGrid)
					{
						if (drv["AllowNulls5"].ToString() == "Y") { yy = yy + 1; }
						else if (drv["AllowNulls5"].ToString() == "N") { nn = nn + 1; } else { zz = zz + 1; }
					}
					int iCnt = dvAdmDbTableGrid.Count - zz;
					if (yy != 0 && yy == iCnt) { bAllowNulls5 = true; } else if (nn == iCnt) { bAllowNulls5 = false; }
					cba.Checked = bAllowNulls5;
				}
				if (cba.Attributes["OnClick"] == null || cba.Attributes["OnClick"].IndexOf("ChkPgDirty") < 0) {cba.Attributes["OnClick"] += "document.getElementById('" + bPgDirty.ClientID + "').value='Y'; ChkPgDirty(); document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			}

			// Take care of aggregates:
			Label aggr = null;
			aggr = cAdmDbTableGrid.FindControl("cColumnLength5fl") as Label;
			if (aggr != null) { aggr.Text = RO.Common3.Utils.fmNumeric("0",GetAggr("ColumnLength5","S"),base.LUser.Culture); }
			aggr = cAdmDbTableGrid.FindControl("cDefaultValue5fl") as Label;
			if (aggr != null) { aggr.Text = RO.Common3.Utils.fmNumeric("0",GetAggr("DefaultValue5","C"),base.LUser.Culture); }
		}

		private string GetButtonId(ListViewItem lvi)
		{
			string ButtonID = String.Empty;
			Control c = lvi.FindControl("cAdmDbTableGridEdit");
			if (c != null) { ButtonID = c.UniqueID; }
			return ButtonID;
		}

		private void SetDefaultCtrl(HtmlTableRow tr, LinkButton lb, string ctrlId)
		{
			tr.Attributes.Add("onclick", "document.getElementById('" + bConfirm.ClientID + "').value='N'; fFocusedEdit('" + lb.UniqueID + "','" + ctrlId + "',event);");
		}

		private int GetCurrPageIndex()
		{
		    return cAdmDbTableGridDataPager.StartRowIndex / cAdmDbTableGridDataPager.PageSize;
		}

		private int GetTotalPages()
		{
		    return (int)Math.Ceiling((double)cAdmDbTableGridDataPager.TotalRowCount / cAdmDbTableGridDataPager.PageSize);
		}

		private int GetDataItemIndex(int editIndex)
		{
		    return cAdmDbTableGridDataPager.StartRowIndex + editIndex;
		}

		protected void cAdmDbTableGrid_OnLayoutCreated(object sender, EventArgs e)
		{
		    // Header:
		    LinkButton lb = null;
		    lb = cAdmDbTableGrid.FindControl("cColumnId5hl") as LinkButton;
		    if (lb != null) { lb.Text = ColumnHeaderText(19); lb.ToolTip = ColumnToolTip(19); lb.Parent.Visible = GridColumnVisible(19); }
		    lb = cAdmDbTableGrid.FindControl("cColumnIndex5hl") as LinkButton;
		    if (lb != null) { lb.Text = ColumnHeaderText(20); lb.ToolTip = ColumnToolTip(20); lb.Parent.Visible = GridColumnVisible(20); }
		    lb = cAdmDbTableGrid.FindControl("cExternalTable5hl") as LinkButton;
		    if (lb != null) { lb.Text = ColumnHeaderText(21); lb.ToolTip = ColumnToolTip(21); lb.Parent.Visible = GridColumnVisible(21); }
		    lb = cAdmDbTableGrid.FindControl("cColumnName5hl") as LinkButton;
		    if (lb != null) { lb.Text = ColumnHeaderText(22); lb.ToolTip = ColumnToolTip(22); lb.Parent.Visible = GridColumnVisible(22); }
		    lb = cAdmDbTableGrid.FindControl("cDataType5hl") as LinkButton;
		    if (lb != null) { lb.Text = ColumnHeaderText(23); lb.ToolTip = ColumnToolTip(23); lb.Parent.Visible = GridColumnVisible(23); }
		    lb = cAdmDbTableGrid.FindControl("cColumnLength5hl") as LinkButton;
		    if (lb != null) { lb.Text = ColumnHeaderText(24); lb.ToolTip = ColumnToolTip(24); lb.Parent.Visible = GridColumnVisible(24); }
		    lb = cAdmDbTableGrid.FindControl("cColumnScale5hl") as LinkButton;
		    if (lb != null) { lb.Text = ColumnHeaderText(25); lb.ToolTip = ColumnToolTip(25); lb.Parent.Visible = GridColumnVisible(25); }
		    lb = cAdmDbTableGrid.FindControl("cDefaultValue5hl") as LinkButton;
		    if (lb != null) { lb.Text = ColumnHeaderText(26); lb.ToolTip = ColumnToolTip(26); lb.Parent.Visible = GridColumnVisible(26); }
		    lb = cAdmDbTableGrid.FindControl("cAllowNulls5hl") as LinkButton;
		    if (lb != null) { lb.Text = ColumnHeaderText(27); lb.ToolTip = ColumnToolTip(27); lb.Parent.Visible = GridColumnVisible(27); }
		    lb = cAdmDbTableGrid.FindControl("cColumnIdentity5hl") as LinkButton;
		    if (lb != null) { lb.Text = ColumnHeaderText(28); lb.ToolTip = ColumnToolTip(28); lb.Parent.Visible = GridColumnVisible(28); }
		    lb = cAdmDbTableGrid.FindControl("cPrimaryKey5hl") as LinkButton;
		    if (lb != null) { lb.Text = ColumnHeaderText(29); lb.ToolTip = ColumnToolTip(29); lb.Parent.Visible = GridColumnVisible(29); }
		    lb = cAdmDbTableGrid.FindControl("cIsIndexU5hl") as LinkButton;
		    if (lb != null) { lb.Text = ColumnHeaderText(30); lb.ToolTip = ColumnToolTip(30); lb.Parent.Visible = GridColumnVisible(30); }
		    lb = cAdmDbTableGrid.FindControl("cIsIndex5hl") as LinkButton;
		    if (lb != null) { lb.Text = ColumnHeaderText(31); lb.ToolTip = ColumnToolTip(31); lb.Parent.Visible = GridColumnVisible(31); }
		    lb = cAdmDbTableGrid.FindControl("cColObjective5hl") as LinkButton;
		    if (lb != null) { lb.Text = ColumnHeaderText(32); lb.ToolTip = ColumnToolTip(32); lb.Parent.Visible = GridColumnVisible(32); }
		    // Hide DeleteAll:
			DataTable dtAuthRow = GetAuthRow();
			if (dtAuthRow != null)
			{
				DataRow dr = dtAuthRow.Rows[0];
				if ((dr["AllowUpd"].ToString() == "N" && dr["AllowAdd"].ToString() == "N") || dr["ViewOnly"].ToString() == "G" || (Request.QueryString["enb"] != null && Request.QueryString["enb"] == "N"))
				{
		            lb = cAdmDbTableGrid.FindControl("cDeleteAllButton") as LinkButton; if (lb != null) { lb.Visible = false; }
				}
			}
		    // footer:
		    Label gc = null;
		    gc = cAdmDbTableGrid.FindControl("cColumnId5fl") as Label;
		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(19); }
		    gc = cAdmDbTableGrid.FindControl("cColumnIndex5fl") as Label;
		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(20); }
		    gc = cAdmDbTableGrid.FindControl("cExternalTable5fl") as Label;
		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(21); }
		    gc = cAdmDbTableGrid.FindControl("cColumnName5fl") as Label;
		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(22); }
		    gc = cAdmDbTableGrid.FindControl("cDataType5fl") as Label;
		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(23); }
		    gc = cAdmDbTableGrid.FindControl("cColumnLength5fl") as Label;
		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(24); }
		    gc = cAdmDbTableGrid.FindControl("cColumnScale5fl") as Label;
		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(25); }
		    gc = cAdmDbTableGrid.FindControl("cDefaultValue5fl") as Label;
		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(26); }
		    gc = cAdmDbTableGrid.FindControl("cAllowNulls5fl") as Label;
		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(27); }
		    gc = cAdmDbTableGrid.FindControl("cColumnIdentity5fl") as Label;
		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(28); }
		    gc = cAdmDbTableGrid.FindControl("cPrimaryKey5fl") as Label;
		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(29); }
		    gc = cAdmDbTableGrid.FindControl("cIsIndexU5fl") as Label;
		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(30); }
		    gc = cAdmDbTableGrid.FindControl("cIsIndex5fl") as Label;
		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(31); }
		    gc = cAdmDbTableGrid.FindControl("cColObjective5fl") as Label;
		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(32); }
		}

		protected void cbPostBack(object sender, System.EventArgs e)
		{
		}

		protected void IgnoreHeaderConfirm(LinkButton lb)
		{
		    if (lb != null && (lb.Attributes["OnClick"] == null || lb.Attributes["OnClick"].IndexOf("_bConfirm") < 0) && lb.Visible) { lb.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';"; }
		}

		protected void IgnoreConfirm()
		{
			if (cExpTxtButton.Attributes["OnClick"] == null || cExpTxtButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cExpTxtButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cExpRtfButton.Attributes["OnClick"] == null || cExpRtfButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cExpRtfButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cUndoAllButton.Attributes["OnClick"] == null || cUndoAllButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cUndoAllButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cSaveCloseButton.Attributes["OnClick"] == null || cSaveCloseButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cSaveCloseButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cSaveButton.Attributes["OnClick"] == null || cSaveButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cSaveButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cInsRowButton.Attributes["OnClick"] == null || cInsRowButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cInsRowButton.Attributes["onclick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cBrowse.Attributes["OnClick"] == null || cBrowse.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cBrowse.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cPgSizeButton.Attributes["OnClick"] == null || cPgSizeButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cPgSizeButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cFirstButton.Attributes["OnClick"] == null || cFirstButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cFirstButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cPrevButton.Attributes["OnClick"] == null || cPrevButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cPrevButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cNextButton.Attributes["OnClick"] == null || cNextButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cNextButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cLastButton.Attributes["OnClick"] == null || cLastButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cLastButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cFindButton.Attributes["OnClick"] == null || cFindButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cFindButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cHideImpButton.Attributes["OnClick"] == null || cHideImpButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cHideImpButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cShowImpButton.Attributes["OnClick"] == null || cShowImpButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cShowImpButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cNewSaveButton.Attributes["OnClick"] == null || cNewSaveButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cNewSaveButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cCopySaveButton.Attributes["OnClick"] == null || cCopySaveButton.Attributes["OnClick"].IndexOf("_bConfirm") < 0) {cCopySaveButton.Attributes["OnClick"] += "document.getElementById('" + bConfirm.ClientID + "').value='N';";}
			if (cDeleteButton.Attributes["OnClick"] == null || cDeleteButton.Attributes["OnClick"].IndexOf("return confirm") < 0) {cDeleteButton.Attributes["OnClick"] += "return confirm('Delete this record for sure?');";}
			if (cClearButton.Attributes["OnClick"] == null || cClearButton.Attributes["OnClick"].IndexOf("return confirm") < 0) {cClearButton.Attributes["OnClick"] += "return confirm('Clear this record for sure and assume initial defaulted values except non-editable fields? You may click the New button if you wish to create a new record instead.');";}
		}

		protected void InitPreserve()
		{
			cSystemId.Attributes["onchange"] = "javascript:return CanPostBack(true,this);";cSystemId.Attributes["NeedConfirm"] = "Y";
			cFilterId.Attributes["onchange"] = "javascript:return CanPostBack(true,this);";cFilterId.Attributes["NeedConfirm"] = "Y";
		}

		protected void ShowDirty(bool bShow)
		{
			if (bShow) {bPgDirty.Value = "Y";} else {bPgDirty.Value = "N";}
		}

		private void PreMsgPopup(string msg) { PreMsgPopup(msg,cAdmDbTable2List,null); }

		private void PreMsgPopup(string msg, RoboCoder.WebControls.ComboBox cb, WebControl wc)
		{
		    if (string.IsNullOrEmpty(msg)) return;
		    if (IsCronInvoked()) { ErrorTrace(new Exception(msg), bErrNow.Value == "N" ? "warning" : "error"); return; }
		    int MsgPos = msg.IndexOf("RO.SystemFramewk.ApplicationAssert");
		    string iconUrl = "images/warning.gif";
		    string focusOnCloseId = cb != null ? cb.FocusID : (wc != null ? wc.ClientID : string.Empty);
		    string msgContent = ReformatErrMsg(msg);
		    if (MsgPos >= 0 && LUser.TechnicalUsr != "Y") { msgContent = ReformatErrMsg(msg.Substring(0, MsgPos - 3)); }
		    if (bErrNow.Value == "Y") { iconUrl = "images/error.gif"; bErrNow.Value = "N"; }
		    else if (bInfoNow.Value == "Y") { iconUrl = "images/info.gif"; bInfoNow.Value = "N"; }
			string script =
			@"<script type='text/javascript' lang='javascript'>
			PopDialog('" + iconUrl + "','" + msgContent.Replace(@"\", @"\\").Replace("'", @"\'") + "','" + focusOnCloseId + @"');
			</script>";
			ScriptManager.RegisterStartupScript(cMsgContent, typeof(Label), "Popup", script, false);
		}

		private Control FindEditableControl(Control root)
		{
		    Control found = null;
		    if (IsEditableControl(root)) { found = root; return found; }
		    foreach (Control c in root.Controls)
		    {
		        found = FindEditableControl(c); if (found != null) return found;
		    }
		    return null;
		}
	}
}

